mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Java: Take into account writes to the field done via AtomicFieldUpdater (IDEA-152262)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
class Atomics {
|
||||
private volatile int num;
|
||||
private static final AtomicIntegerFieldUpdater<Atomics> updater =
|
||||
AtomicIntegerFieldUpdater.newUpdater(Atomics.class, "num");
|
||||
|
||||
public int getInt() {
|
||||
return updater.get(this);
|
||||
}
|
||||
|
||||
public int getAndSet(int n) {
|
||||
return update(updater::getAndSet, n);
|
||||
}
|
||||
|
||||
private int update(BiFunction<Atomics, Integer, Integer> f, int n) {
|
||||
return f.apply(this, n);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user