我想知道這個表達式是否正確,如果是這樣的話:我在字段狀態上寫了一個鎖,並且比我更改它。如果不是,我想知道參數的含義是什麼,因爲我總是看到這個。關於參數塊同步的含義的說明
public class Example {
private int status;
public Example(int status){
this.status = status;
}
public void setStatus(int newStatus){
synchronized(this.status){
this.status = newStatus;
}
}
}
我在示例中使用了一個基元,但在我的項目中我使用了一個對象 – Oxenarf
@Oxenarf - 您仍然無法更改您在setter中鎖定的對象。 – OldCurmudgeon