昨天面试的一道题# Java - 爪哇娇娃
g*e
1 楼
class Num {
private Integer i = 0;
public synchronized void set(int i) {
this.i = i;
}
public synchronized int get() {
return i;
}
public synchronized void swap(Num other) {
//implement a thread safe swap method here.
}
}
private Integer i = 0;
public synchronized void set(int i) {
this.i = i;
}
public synchronized int get() {
return i;
}
public synchronized void swap(Num other) {
//implement a thread safe swap method here.
}
}