Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created November 8, 2016 14:57
Show Gist options
  • Save chermehdi/61e751d8461ec82e90865c710330f171 to your computer and use it in GitHub Desktop.
Save chermehdi/61e751d8461ec82e90865c710330f171 to your computer and use it in GitHub Desktop.
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