繁体   English   中英

扩展 java class<t extends someclass> kotlin 中的泛型类型</t>

[英]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?

我已经尝试过使用 out 关键字,但这并不好。

EntityFragment.java

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

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

我正在尝试编写的 kotlin class 如下:

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

在这种情况下,您不应该使用out关键字。 你可以写

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM