Not exactly what you want but should work:
interface A {
val f: B
}
interface B {
val f: A
}
data class AImpl(override var f: B) : A
data class BImpl(override var f: A) : B
fun <T> uninitialized(): T = null as T
fun foo() {
var aImpl = AImpl(uninitialized())
var bImpl = BImpl(aImpl)
aImpl.f = bImpl
val a: A = aImpl
val b: B = bImpl
}
If you do not care about data class properties being val
s, you can get rid of interfaces and use just implementation classes.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…