Joshua Hansen
11/19/2025, 7:25 PMinterface TestT: Number {
val clazz: KClassT // Keep reference to the class so we can find the right one later
fun foo(item: T)
}
// Int object:
object A : TestInt {
override val clazz = Int::class
override fun foo(item: Int) {
// do something
}
}
// Double object
object B : TestDouble {
override val clazz = Double::class
override fun foo(item: Double) {
// do something
}
}
fun test() {
// Working with a list of these objects
val objs: List<Testout Number> = listOf(A, B)
val myInt = 1
// I'm certain find returns A, but due to forced out projection I get an error.
val properObj = objs.find {
it.clazz == myInt::class
}
properObj?.foo(myInt) // Receiver type 'Testout Number' contains out projection which prohibits the use of 'fun foo(item: T): Unit'.
}Coty Saxman
11/20/2025, 7:38 AM