【发布时间】:2021-03-30 06:53:40
【问题描述】:
所以我有一个泛型类型的类
class GenericClass<T> {
// At some point in the class I have variable item of type T
val name: String = item.name
}
我确信 GenericClass 的类型 T 将与具有“名称”属性的类一起使用。但当然,我得到了一个“未解决的参考名称”。 Android Studio 通过“创建扩展属性 T.name”为我生成了这段代码
private val <T> T.name: String
get() {}
我真的不知道在 get 之后在括号 {} 中放什么。我尝试了return name,但出现递归属性错误。
有什么想法吗?
谢谢
【问题讨论】: