https://kotlinlang.org logo
Title
c

Chris Margonis

04/17/2018, 4:58 PM
Uhm this may sound dumb, but is it possible to use a
lateinit var
inside a
by lazy {...}
block of another
val
? I get the
UninitializedPropertyAccessException
when the class is being created.
a

andyb

04/19/2018, 7:20 AM
Yep, pretty sure that I am doing that with the auto-wiring of Spring Components. Are you sure that the dependency is being initialised?
c

Chris Margonis

04/20/2018, 5:03 AM
The thing is that there's no constructor or init logic in general. The lateinit property is being initialized later on. I checked the bytecode generated for the class and in there there's a check (during init) whether the lateinit parameter passed in a lazy block is zero. At that point it indeed is zero thus the exception. Thanks for taking the time to reply :)