title: How to use Java Optional to elegantly replace Ternary operators
body: <p>A super simple question:</p>
  <p>Here's my plain Java code using traditional ternary operator <code>?</code></p>
  <pre><code>public DateTime getCreatedAt() {
      return !recordA.isPresent() ? recordB.get().getCreatedAt() : recordA.get().getCreatedAt();
  }
  </code></pre>
  <p>My best bet is following:</p>
  <pre><code>public DateTime getCreatedAt() {
      return recordA.map(
          record -&gt; record.getCreatedAt())
          .orElse(recordB.get().getCreatedAt());
    }
  </code></pre>
  <p>This could compile, but looks like it's not behaving correctly.
  It always executes both branches, for e.g. when <code>recordA</code> isPresent(), it still executes <code>recordB.get().getCreatedAt()</code> which throws me</p>
  <pre><code>java.util.NoSuchElementException: No value present
  </code></pre>
  <p>Any help is appreciated!</p>
  <p>Basically, I'd like to replace the traditional ternary operator with more advanced Optional/lamda features.</p>