"predictions not allowed for direct supertype arguments" Kotlin Android Studio

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);
    }
}

      

Kotlinsky

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

      

Android Studio says the following:

predictions not allowed for immediate supertype arguments

What do I need to change here?

+3


source to share


1 answer


Use Any

for a quick fix, or enter a type parameter to make sure you are not violating the library's type safety.

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

or



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

The problem is that kotlin requires class types to be fully defined, so you can specify a specific type as a type parameter, or go through a new type parameter.

+4


source







All Articles