mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-17 15:50:53 +07:00
16 lines
503 B
Java
16 lines
503 B
Java
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
|
|
import java.util.function.BiFunction;
|
|
|
|
class Atomics {
|
|
private volatile String str;
|
|
private static final AtomicReferenceFieldUpdater<Atomics, String> updater =
|
|
AtomicReferenceFieldUpdater.newUpdater(Atomics.class, String.class, "str");
|
|
|
|
public String getAndSet(String s) {
|
|
return update(updater::getAndSet, s);
|
|
}
|
|
|
|
private String update(BiFunction<Atomics, String, String> f, String s) {
|
|
return f.apply(this, s);
|
|
}
|
|
} |