Design-Patterns-In-Kotlin
Design-Patterns-In-Kotlin copied to clipboard
Add LazyThreadSafeSingleton code and test
Hi,
I add the lazy thread safe singleton pattern example. Please kindly check and review. Thank you.
Best regards,
Maikel
Object is also lazy at a class level, it won't get initialised until you will reference class.
See "decompiled" byte code https://stackoverflow.com/a/54053195/361832
It only makes sense if you have more then one instance field which seams very rare and potentially breaking single responsibility principle.
yeah I know. It is more to variant or improvement of normal singleton pattern, and I was trying to implement the double-check locking singleton in Kotlin. Furthermore, thats why I didn't update the readme :)