I'd like to provide multiple different delegates from a single class, with differing types. For example:
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 {}
This example gives the following compiler error:
'operator' modifier is inapplicable on this function: second parameter must be of type KProperty<*> or its supertype
Is there some way to specify the generic type arguments such that I can achieve this?