https://kotlinlang.org logo
#announcements
Title
# announcements
s

streetsofboston

08/28/2019, 8:20 PM
Yup, Similar to
Copy code
abstract class A(val a: A?)

object B: A(C)
object C: A(B)
...
println("${B.a} and ${C.a}")
It’s a circular definition. The loading of the classes by the JVM determines which will be
null
and which will be properly initialized.
e

edwinRNDR

08/28/2019, 8:41 PM
I wouldn't hate the editor and/or compiler generate a warning in this case
s

streetsofboston

08/28/2019, 8:42 PM
It may slow the compiler down too much if it has to analyze the code for this type of situation. In the above example, the circular definition is trivial and simple, but you can make a circular definition very deep and non-trivial.
2 Views