title: Alternative for Null Coalescing Operator
body: <p>With Java, to safely access a deep nested reference like
  <code>a.b.c.d.e</code>, we'd usually have to specify null checks at each level or wrap in <code>Optional</code>s and use <code>orElse()</code>. (Unlike with languages like Kotlin/C# where <code>a?.b?.c?.d?.e</code> or similar works.</p>
  
  <p>I was wondering if the following helper method could be a reasonable alternative:</p>
  
  <pre><code>public &lt;T&gt; T valueOrNull(Supplier&lt;T&gt; expression) {
      try {
          return expression.get();
      } catch (NullPointerException e) {
          return null;
      }
  }
  </code></pre>
  
  <p>This can then be used safely with <code>value = valueOrNull(() -&gt; a.b.c.d.e)</code>.</p>
  
  <p>Note: I understand that catching <code>NullPointerException</code>s is usually frowned upon because of performance reasons and more, but was wondering if the usage here would be a reasonable exception.</p>