I have a lazy transient property in a `<http://jav...
# announcements
r
I have a lazy transient property in a
<http://java.io|java.io>.Serializable
class. However accessing
foo
from
@delegate:Transient val foo: Foo by lazy { }
causes a NPE on deserialization. How can I create a lazy property that the VM does not try to serialize, but at the same time does the right thing?
r
Don’t use lazy or Don’t use seriazable?
r
No choice on the
Serializable
as its inherited from Apache Beam (and it uses it). Not using
lazy
is an option, but first I wanted to see if there was a way to make it work.
g
You probably should also annotate getter with Transient, @get:Transient
r
Tried that, results in a compile error
g
What kind error?
r
This annotation is not applicable to target 'member property with delegate' and use site target '@get'
r
if i had to guess the private nullable variable isn’t getting those annots propegated to it
i’ve stopped using lazy due to all the hiccups
r
I've worked around it by storing an `@Transient var`(non-lazy), and then re-setting it in
readObject
. There must be a more elegant approach though.