If you have a Java Singleton that looks like this:
public class MySingleton {
private static MySingleton instance;
private int member;
public static MySingleton getInstance(){
if(instance==null){
instance = new MySingleton();
}
return instance;
}
private MySingleton(){
//empty private constructor
}
public int getMemberA(){
return member;
}
public int getMemberB(){
return instance.member;
}
}
...is there a difference between getMemberA and getMemberB? That is, is there a difference between accessing the member with instance.xxx
and just xxx
?
Note: I am aware of the pros and cons of using the Singleton pattern!