通用扩展 class 并在 Kotlin 中实现接口

Generic extending class AND implements interface in Kotlin

假设我想要一个类型变量 T,它扩展了某个 class 并实现了一个接口。类似于:

class Foo <T : Bar implements Baz> { ... }

Kotlin 中的语法是什么?

尖括号内只能指定一个上限。

当存在多个约束时,Kotlin 为通用约束提供了不同的语法:

class Foo<T>(val t: T) where T : Bar, T : Baz { ... }

对于函数:

fun <T> f(): Foo where T : Bar, T : Baz { ... }

已记录 here