“不允许将投影用于超类型的直接参数". Kotlin Android Studio [英] "projections are not allowed for immediate arguments of a supertype" Kotlin Android Studio
问题描述
将Java转换为Kotlin时出现此错误:
I am getting this error when I converted Java to Kotlin:
Java
public class HeaderTab extends ExpandableGroup {
private String header;
public HeaderTab(String title, List items) {
super(title, items);
}
}
科特林
class HeaderTab(title: String, items: List<*>) : ExpandableGroup<*>(title, items) {
private val header: String? = null
}
Android Studio这样说:
Android Studio says this:
超类型的直接参数不允许使用投影
projections are not allowed for immediate arguments of a supertype
我需要在这里修改什么?
What do I need to modify here?
推荐答案
使用Any
快速修复,或引入类型参数以确保不破坏库的类型安全性.
Use Any
for a quick fix, or introduce a type parameter to make sure you don't break the type safety of the library.
class HeaderTab(title: String, items: List<*>) : ExpandableGroup<Any>(title, items) {
或
class HeaderTab<E>(title: String, items: List<E>) : ExpandableGroup<E>(title, items) {
问题在于kotlin要求完全指定类类型,因此您可以将特定类型指定为类型参数,也可以通过新的类型参数传递.
The problem is that kotlin requires class types to be fully specified, so you can either specify a specific type as a type parameter or pass through a new type parameter.
这篇关于“不允许将投影用于超类型的直接参数". Kotlin Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!