"对超类型"Kotlin Android Studio的即时论证不允许进行预测

use*_*306 6 java android kotlin android-studio kotlin-android-extensions

当我将Java转换为Kotlin时,我收到此错误:

Java的

public class HeaderTab extends ExpandableGroup {
    private String header;

    public HeaderTab(String title, List items) {
        super(title, items);
    }
}
Run Code Online (Sandbox Code Playgroud)

科特林

class HeaderTab(title: String, items: List<*>) : ExpandableGroup<*>(title, items) {
    private val header: String? = null
}
Run Code Online (Sandbox Code Playgroud)

Android Studio说:

对于超类型的直接参数,不允许进行投影

我需要在这里修改什么?

Kis*_*kae 11

使用Any速战速决,或引入一个类型参数,以确保你不破库的类型安全.

class HeaderTab(title: String, items: List<*>) : ExpandableGroup<Any>(title, items) {

要么

class HeaderTab<E>(title: String, items: List<E>) : ExpandableGroup<E>(title, items) {

问题是kotlin需要完全指定类类型,因此您可以指定特定类型作为类型参数或传递新的类型参数.