title: Atomic compareAndSet but with callback?
body: <p>I know that <code>AtomicReference</code> has <code>compareAndSet</code>, but I feel like what I want to do is this</p>
  
  <pre><code>private final AtomicReference&lt;Boolean&gt; initialized = new AtomicReference&lt;&gt;( false );
  ...
  
  atomicRef.compareSetAndDo( false, true, () -&gt; {
    // stuff that only happens if false
  });
  </code></pre>
  
  <p>this would probably work too, might be better.</p>
  
  <pre><code>atomicRef.compareAndSet( false, () -&gt; {
    // stuff that only happens if false
    // if I die still false.
  
     return true;
  });
  </code></pre>
  
  <p>I've noticed there's some new functional constructs but I'm not sure if any of them are what I'm looking for.</p>
  
  <p>Can any of the new constructs do this? if so please provide an example.</p>
  
  <p><strong>update</strong>
  To attempt to simplify my problem, I'm trying to find a less error prone way to guard code in a "do once for object" or (really) lazy initializer fashion, and I know that some developers on my team find <code>compareAndSet</code> confusing.</p>