我想从一个类中提供多个不同类型的不同代表。例如:
class A {
val instanceOfB = B()
val aNumber: SomeType by instanceOfB
val anotherNumber: SomeOtherType by instanceOfB
}
class B {
operator fun <T1: SomeType> getValue(thisRef: Any?, property: KProperty<T1>): T1 {
return SomeType()
}
operator fun <T2: SomeOtherType> getValue(thisRef: Any?, property: KProperty<T2>): T2 {
return SomeOtherType()
}
}
open class SomeType {}
open class SomeOtherType {}
此示例给出以下编译器错误:
'operator' modifier is inapplicable on this function: second parameter must be of type KProperty<*> or its supertype
有没有办法指定泛型类型参数以便我可以实现这一点?