rtsketo
03/31/2022, 4:55 PMopen class A {
open fun somFun(lambda: (suspend A.() -> Unit)? = null) = apply { /* ... */ }
}
class B : A()
class C {
/**
* Type mismatch.
* Required: B
* Found: A
*/
val b: B = B().somFun { }
}
Is there a way to return B instead of A in B().somFun { }
without using a static function like below?
open class A {
companion object {
fun <T : A> T.somFun(lambda: (suspend T.() -> Unit)? = null) = apply { /* ... */ }
}
}
Like, is there a way to have <out A> in a lambda?ephemient
03/31/2022, 5:18 PM