Kotlin class 具有泛型和实现接口
Kotlin class with generics and implementing interfcae
我在 Android
开发中使用 Kotlin
,我想用两个泛型创建 class,其中之一 V
必须是子 class View
,class 也应该实现一些接口 MyInterface
。
怎么做?我试过这样的东西
class Test<T, V>(val value1: String, val map: Map<T, V>) where V: View, MyInterface
或
class Test<T, V>(val value1: String, val map: Map<T, V>) where V: View: MyInterface
但我不知道正确的语法是什么?
class Test<T, V: View> (val string: String, val map: Map<T, V>) : MyInterface
应该是正确的语法。
我在 Android
开发中使用 Kotlin
,我想用两个泛型创建 class,其中之一 V
必须是子 class View
,class 也应该实现一些接口 MyInterface
。
怎么做?我试过这样的东西
class Test<T, V>(val value1: String, val map: Map<T, V>) where V: View, MyInterface
或
class Test<T, V>(val value1: String, val map: Map<T, V>) where V: View: MyInterface
但我不知道正确的语法是什么?
class Test<T, V: View> (val string: String, val map: Map<T, V>) : MyInterface
应该是正确的语法。