Darryl Miles
04/05/2024, 12:34 AMprivate var myThing: MyThing? = null is the current form in use.
The item is initialize via a @PostConstruct method, but I don't want to use myThing!! every time I use it.
ThanksYoussef Shoaib [MOD]
04/05/2024, 12:36 AMlateinit var myThing: MyThingDarryl Miles
04/05/2024, 12:37 AMPablichjenkov
04/05/2024, 12:37 AMvar myThing: MyThing = EmptyObjectThing()Pablichjenkov
04/05/2024, 12:41 AMval myThingNonNull = myThing ?: return
myThingNonNull.foo()Darryl Miles
04/05/2024, 12:42 AMlateinit looks more correct, but it will be a few minutes before I validate the answer. My talk of using a @PostConstruct implies I have complex initialization of this item, and the assumption I have a compatible instance of the type to use as a placeholder (in the language construction of the object) until I re-assign it in fun postConstruct() {} would not work such as var myThing = MyThing.emptyPlaceholder() as the type is too complexPablichjenkov
04/05/2024, 12:53 AMPablichjenkov
04/05/2024, 12:53 AM!!Darryl Miles
04/05/2024, 1:03 AM!! appears and the eyesore that produces, for a scenario that if it is found to be a null value should raise an exception at runtime, because it will be a programming error that needs a fix (not a runtime error recovery, which is the function of exceptions). Thanks for your reply.Pablichjenkov
04/05/2024, 1:06 AMlateinit will be the man for the job.Stephan Schröder
04/05/2024, 7:49 AMlateinit