Is it appropriate to use AtomicReference with a java lambda?

3.2k views Asked by At

I often find myself using this idiom:

AtomicReference<MyCoolObject> coolReference = new AtomicReference(new MyCoolObject());

getOptionalValue().ifPresent(presentValue -> {
  coolReference.set(new MyCoolObject(presentValue));
});
return coolReference.get(); 

Is this a bad habit, or a legitimate use of AtomicReference?

0

There are 0 answers