I have generic interface...
interface Parent<T> {
fun function(entity: T): Int
}
And when I implement functionality with some child class...
class Other : Parent<Other> {
override fun function(entity: Other): Int {
return 42
}
}
I'm bothered with the fact that I have to pass the same class type while implementing the interface... I would really like for the interface to be able to detect on which class is attached on its own without me providing the same type again...
I would like code something like this...
class Other : Parent {
override fun function(entity: Other): Int {
return 42
}
}
Is it possible in kotlin to do that in some form?
CodePudding user response:
Not in the general case, but sometimes when a generic is fully constrained by another: https://kotlinlang.org/docs/generics.html#underscore-operator-for-type-arguments
CodePudding user response:
It looks like that this was in proposal for quite some time... If anyone alse missing this feature lets show interest for implmeneting this feature here: https://youtrack.jetbrains.com/issue/KT-6494