0
public Foo{
private Object mutex = new Object();
private int bar;
public Foo(Foo f){
this.mutex = f.getMutex();
this.bar = f.getBar();
}
public Object getMutex(){
return mutex;
}
public void setBar(int bar){
synchronized(mutex){
this.bar = bar;
}
}
public int getBar(){
synchronized(mutex){
return bar;
}
}
}
什麼是f('f.getMutex()')? – 2012-07-09 18:50:02
取決於你想讓這個類表現如何,但絕對要讓這個互斥量數據成員最終。 – wolfcastle 2012-07-09 18:52:30