package com.michaelthomas.singleton; /** * @author Michael Thomas (www.michael-thomas.com) michael@michael-thomas.com * * Note: Original concepts came from Wikipedia.com * http://en.wikipedia.org/wiki/Singleton_pattern */ public enum SingletonJVMEnumExample { INSTANCE; /* * Traditional way to create a Singleton. The INSTANCE is created as soon as * the Singleton class is initialized by the JVM (not lazy). This solution * is thread-safe without requiring special language constructs (i.e. * volatile or synchronized). */ private String name; // Private constructor prevents instantiation from other classes private SingletonJVMEnumExample() { } public void setName(String name) { this.name = name; } public String getName() { return name; } }