|
|
|
|
|
by Tiomaidh
5454 days ago
|
|
public class Singleton {
private static Singleton self = null;
private Singleton() {
//...
}
public static Singleton getInstance() {
if(self == null) {
self = new Singleton();
}
return self;
}
...
}
So at any point in your code you can call Singleton.getInstance() to have access to the same Singleton object. So it's effectively the same thing as a global variable.Edit: Added `static' to be more correct. |
|
It has to be:
private static Singleton self = null;