Created
November 8, 2016 14:57
-
-
Save chermehdi/61e751d8461ec82e90865c710330f171 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.Serializable; | |
public class SimpleSingleton implements Serializable { | |
private static long serialVersionUID = 1L; | |
// this will hold the instance of the class | |
private static SimpleSingleton instance = new SimpleSingleton(); | |
// this will be our constructor it's empty for no reason you can put | |
// anything necessary to instantiate your class | |
private SimpleSingleton() { | |
} | |
// this is the static method to return the instance of the class | |
public static SimpleSingleton getInstance() { | |
return instance; | |
} | |
protected Object readResolve() { | |
return getInstance(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment