LeoColman
12/11/2020, 4:49 PM@No-Arg
data class MyClass(val foo: String) {
val bar by lazy { foo[0] }
}
// Create Foo through reflection, for example, getting it from a database. It will use the zero-arg constructor
val myFoo = getFoo()
myFoo.bar -> NullPointerException
When inspecting the bytecode, the bar$delegate (or something like this) is not initialized in the no-arg constructor, and thus is null in runtime. Do anybody have an idea on how to solve this?LeoColman
12/11/2020, 4:52 PMnoArg {
invokeInitializers = true
}
LeoColman
12/11/2020, 4:52 PMLeoColman
12/11/2020, 5:28 PM