Hey guys! I'm facing some issues with the no-arg p...
# announcements
l
Hey guys! I'm facing some issues with the no-arg plugin + lazy initialization:
Copy code
@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?
Found the solution
Copy code
noArg {
    invokeInitializers = true
}
If anyone wants to favorite this for your future selves, I wrote a stackoverflow question + answer on it
👍 1