hisham bin awiad
10/31/2021, 1:16 PMprivate val empID
get() = (userModelId ?: session.getUserModelId().toSafetyString()).toSafetyString()
private val empID2 by lazy { (userModelId ?: session.getUserModelId().toSafetyString()).toSafetyString() }sbyrne
10/31/2021, 1:38 PMget(), it will be evaluated every time empID is referenced. With by lazy it will only be evaluated once at most.sbyrne
10/31/2021, 1:40 PMuserModelId is immutable and session.getUserModelId() will always return the same thing, use by lazy.hisham bin awiad
10/31/2021, 2:07 PMRobert Williams
11/01/2021, 9:05 AMby lazy also has to synchronise threads on every access to guarantee the single executionRobert Williams
11/01/2021, 9:05 AMLazyThreadSafetyMode.NONE (this will break the single execution guarantee but in this case it probably doesn't matter)Robert Williams
11/01/2021, 9:07 AMprivate val empID = (userModelId ?: session.getUserModelId().toSafetyString()).toSafetyString()Matteo Mirk
11/23/2021, 8:41 AMsession.getUserModelId() can be changed to property accessor session.userModelId