当我将 Java 转换为 Kotlin 时出现此错误:
Java
public class HeaderTab extends ExpandableGroup {
private String header;
public HeaderTab(String title, List items) {
super(title, items);
}
}
Kotlin
class HeaderTab(title: String, items: List<*>) : ExpandableGroup<*>(title, items) {
private val header: String? = null
}
Android Studio 是这样说的:
projections are not allowed for immediate arguments of a supertype
这里需要修改什么?
最佳答案
使用 Any
快速修复,或引入类型参数以确保不会破坏库的类型安全性。
class HeaderTab(title: String, items: List<*>) : ExpandableGroup<Any>(title, items) {
或
class HeaderTab<E>(title: String, items: List<E>) : ExpandableGroup<E>(title, items) {
问题在于 kotlin 需要完全指定类类型,因此您可以指定特定类型作为类型参数,也可以通过新的类型参数。
关于java - "projections are not allowed for immediate arguments of a supertype"Kotlin Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44058972/