Created
December 20, 2013 17:49
-
-
Save algorithmcardboard/8058617 to your computer and use it in GitHub Desktop.
Eager loading singleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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