Example usecase:
fun <T : SomeClass> T.someFunc(...): OtherClass<T> {
return OtherClass<T>(...)
}
This way:
class X(...) : SomeClass(...)
myX = X()
myX.someFunc(...) // return type: OtherClass<X>
Right now I have to define this function outside of the SomeClass class definition, but there should be a way for kotlin to support this.
The alternative I’m using right now is
class SomeClass {
// ...
fun someFunc(...): OtherClass<SomeClass> {
return OtherClass<SomeClass>(...)
}
}
This way:
class X(...) : SomeClass(...)
myX = X()
myX.someFunc(...) // return type: OtherClass<SomeClass>
which, while similar, doesn’t give the results I want, as it returns OtherClass<SomeClass> at all times even when called from a subclass.