8

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

Kotlin

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

Android Studio says this:

projections are not allowed for immediate arguments of a supertype

What do I need to modify here?

user3124306
  • 685
  • 1
  • 9
  • 20

1 Answers1

11

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) {

or

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

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.

Kiskae
  • 24,655
  • 2
  • 77
  • 74
  • Now wonder what the Kotlin team tried to do and whether they achieved what they wanted?! Probably not. There is always a quick fix to their "strict" rules that they think the Java core team failed (and fails) to solve. Almost same crap with different syntax and name – Farid Oct 11 '21 at 11:29