Skip to content

Instantly share code, notes, and snippets.

@algorithmcardboard
Created December 20, 2013 17:49
Show Gist options
  • Save algorithmcardboard/8058617 to your computer and use it in GitHub Desktop.
Save algorithmcardboard/8058617 to your computer and use it in GitHub Desktop.
Eager loading singleton
package in.rajegannathan.singletons;
/**
* Example class for a eager loading singleton.
* The declaration of instance - instance variable should have both static and final.
* Without final we might lose the initialization safety that final provides
*/
public class EagerSingleton {
private static final EagerSingleton instance = new EagerSingleton();
private EagerSingleton(){
}
public static EagerSingleton getInstance(){
return instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment