user1381126
user1381126

Reputation: 73

How create list with generic argument in Kotlin

I have a interface:

interface SomeInterface<T>{

}

In java i can declare list as follows:

List<SomeInterface> list = new ArrayList<>();

How to write the same in Kotlin? If i try this:

var list = ArrayList<PreferenceSerializer>()

I get an error an error

Upvotes: 6

Views: 9222

Answers (1)

Jorn Vernee
Jorn Vernee

Reputation: 33865

Kotlin doesn't have raw types. Since SomeInterface is generic, you would need to parametrize it. For instance with a wildcard:

var list = ArrayList<SomeInterface<*>>()

Upvotes: 18

Related Questions