例如我有一个这样的类:
public class StaticObjectReference{
private static StaticObjectReference instance;
private Vector queue;
public static StaticObjectReference getInstance(){
if(instance == null){
instance = new StaticObjectReference();
}
return instance;
}
public Vector getQueue(){
queue = new Vector();
return queue;
}
}
接下来的两个类称为StaticObjectReference
类。
public class CallerOne{
Vector queue1;
public void callObjectInstance1(){
queue1 = StaticObjectReference.getInstance().getQueue();
}
}
class CallerTwo{
Vector queue2;
public void callObjectInstance2(){
queue2 = StaticObjectReference.getInstance().getQueue();
}
}
CallerOnequeue1
类中的 是 CallerTwo 类中的同一个实例queue2
吗?