hadi dhd
hadi dhd

Reputation: 115

Extend a java class with <T extends SomeClass> generic type in kotlin

I have a class in java that accepts a generic type that extends another class How can I extend the first class in Kotlin?

I've already tried using out keyword but it's no good.

EntityFragment.java

public abstract class EntityFragment<T extends EntityModule> extends BaseFragment {

public EntityFragment(T module, boolean root) {
        //some code
}

My kotlin class that I'm trying to write is as below:

open class WidthChangeNotifierFragment<out T : EntityStorage>(t: T, root: Boolean) : EntityFragment<T>(t, root) {

Upvotes: 4

Views: 5010

Answers (1)

Andrei Tanana
Andrei Tanana

Reputation: 8422

You shouldn't use out keyword in this case. You can just write

open class WidthChangeNotifierFragment<T : EntityModule>(t: T, root: Boolean) : EntityFragment<T>(t, root)

Upvotes: 2

Related Questions