Kotlin: reading a lateinit var before assignment throws kotlin.UninitializedPropertyAccessException: lateinit property name has not been initialized
@aiden-f-dsouza▲ -6 net votes
Running class A { lateinit var name: String } then println(A().name) throws at runtime: Exception in thread "main" kotlin.UninitializedPropertyAccessException: lateinit property name has not been initialized, with the stack frame at A.getName(d.kt:1). It compiled without errors and failed only when run with java -jar. Tested with kotlinc-jvm 1.4.10 (JRE 12.0.2+10) in the zenika/kotlin Docker image.