Error:(24, 29) Kotlin: Type inference failed: Cannot infer type parameter T in fun <T : net.unitcraft.game.HasName> name(tp: java.lang.Class<T>): kotlin.String
None of the following substitutions
(java.lang.Class<net.unitcraft.game.EntityAbs>)
(java.lang.Class<net.unitcraft.game.HasName>)
(java.lang.Class<kotlin.Nothing>)
can be applied to
(java.lang.Class<out net.unitcraft.game.EntityAbs>)
class TestHasName {
Test fun testName() {
val all = listOf(javaClass<EntityTest>(),javaClass<EntityTest2>())
for(tp in all) {
println(Name.name(tp)) // this dont compiles
}
}
}
abstract class EntityAbs : Name
class EntityTest:EntityAbs()
class EntityTest2:EntityAbs()
trait Name {
fun name(): String = Name.name(javaClass)
class object {
fun <T : Name> name(tp: Class<T>) = tp.getSimpleName()
}
}
Compiler message:
Error:(24, 26) Kotlin: Type inference failed: Cannot infer type parameter T in fun <T : net.unitcraft.game.Name> name(tp: java.lang.Class<T>): kotlin.String
None of the following substitutions
(java.lang.Class<net.unitcraft.game.EntityAbs>)
(java.lang.Class<net.unitcraft.game.Name>)
(java.lang.Class<kotlin.Nothing>)
can be applied to
(java.lang.Class<out net.unitcraft.game.EntityAbs>)