How to use Enum as Singleton in Java with Example

Synopsis

From Java 5 onwards there is a new way to implement Singleton design pattern, by using Enum. Enum has some distinct benefits in terms of thread-safety

Statistics

  • Total Hits - 40271

  • Total Votes - 137 votes

  • Vote Up - 58 votes

  • Vote Down - 79 votes

  • Domain - javarevisited.blogspot.com

  • Category - JAVA/Getting Started

  • Submitted By - Javin Paul

  • Submitted on - 2012-11-01 15:37:10

Description

From Java 5 onwards there is a new way to implement Singleton design pattern, by using Enum. Enum has some distinct benefits in terms of thread-safety during instance creation, serialization guarantee by JVM and amazingly reduce amount of code which makes it perfect choice of using as Singleton class.

Source Website

Please use the following link to visit the site. There is a possibility that this content has been removed from the given URL or may be this site has been shut down completely.

http://javarevisited.blogspot.com/2012/07/why-enum-singleton-are-better-in-java.html

Broken  |   Save  |   Liked  |   Down

Advertisements