public final long updateAndGet(LongUnaryOperator updateFunction){
  long prev, next;
  do {
    prev=get();
    next=updateFunction.applyAsLong(prev);
  }
 while (!compareAndSet(prev,next));
  return next;
}

public final long updateAndGet ( LongUnaryOperator updateFunction ) { long prev , next ; do { prev = get ( ) ; next = updateFunction . applyAsLong ( prev ) ; } while ( ! compareAndSet ( prev , next ) ) ; return next ; }
atomically updates the current value with the results of applying the given function , returning the updated value . the function should be side - effect - free , since it may be re - applied when attempted updates fail due to contention among threads .
