Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) {
like image 764
hadi dhd Avatar asked Oct 27 '25 13:10

hadi dhd


1 Answers

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)
like image 57
Andrei Tanana Avatar answered Oct 30 '25 06:10

Andrei Tanana