假设我想要一个类型变量T,它扩展了某个类并实现了一个接口.比如:
class Foo <T : Bar implements Baz> { ... }
What is the syntax for this in Kotlin?
假设我想要一个类型变量T,它扩展了某个类并实现了一个接口.比如:
class Foo <T : Bar implements Baz> { ... }
What is the syntax for this in Kotlin?
Only one upper bound can be specified inside the angle brackets.
当存在多个约束时,Kotlin为通用约束提供了不同的语法:
class Foo<T>(val t: T) where T : Bar, T : Baz { ... }
and for functions:
fun <T> f(): Foo where T : Bar, T : Baz { ... }
It is documented here.