Design-Patterns-In-Kotlin icon indicating copy to clipboard operation
Design-Patterns-In-Kotlin copied to clipboard

Add LazyThreadSafeSingleton code and test

Open mkdika opened this issue 6 years ago • 2 comments

Hi,

I add the lazy thread safe singleton pattern example. Please kindly check and review. Thank you.

Best regards,

Maikel

mkdika avatar Oct 14 '19 16:10 mkdika

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.

dbacinski avatar Oct 14 '19 18:10 dbacinski

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 :)

mkdika avatar Oct 15 '19 02:10 mkdika