Alexander Eckert
03/13/2020, 1:30 PMclass MyClass<T : Comparable<T>> {
fun join(other : MyClass<T>) {
// so some stuff
}
}
fun someFunction(a : Any, b : Any) {
val instanceA = a as MyClass<*>
val instanceB = b as MyClass<*>
instanceA.join(instanceB)
}
streetsofboston
03/13/2020, 1:38 PMfun <T: Comparable<T>> someFunction2(a : T, b : T) {
val instanceA = a as MyClass<T>
val instanceB = b as MyClass<T>
instanceA.join(instanceB)
}
fun someFunction3(a : Any, b : Any) {
val instanceA = a as MyClass<Comparable<Comparable<*>>>
val instanceB = b as MyClass<Comparable<Comparable<*>>>
instanceA.join(instanceB)
}
(both use unsafe type-casts; you can pass values to a
and b
that will make these two throw an exception)Alexander Mikhalchenko
03/13/2020, 1:43 PMjoin
method signature like this
fun join(other : MyClass<*>)
and this works as well. But signature change may not cover all your usecases of join
ofcourse.Alexander Eckert
03/13/2020, 1:45 PMKroppeb
03/13/2020, 2:48 PM