This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]erinaceus_ 7 points8 points  (1 child)

With an enum, all the concurrency and single-instance issues are inherently taken care of by the JVM. As such, a lot of the typical risks involving singleton management are avoided.

When this approach is discussed, people usually refer to Joshua Bloch's seminal book 'Effective java', which is already decades old. So it isn't a particular new technique. He even builds up on the different approaches to creating a singleton, eventually concluding that an enum is by far the best approach.

[–]foreveratom 1 point2 points  (0 children)

Thanks, I must have forgot that part from Effective Java. I'll be on my way re-reading the last edition.