title: Use java.util.Optional to return null for subfield of Optional type
body: <p>Is it possible to test an <code>Optional</code> and return either 1) a subfield (or method) of the instance being tested or 2) null if the instance being tested is null?</p>
  
  <p>Here's an example (doesn't compile):</p>
  
  <pre><code>public static void main(String[] args) {
  
      A a1 = null;
  
      LocalDate a_date_field = Optional.ofNullable(a1).orElse(???).date; // &lt;--- I need this line ...
      LocalDate a_date_field = a1 == null? null : a1.date; // &lt;---- ... to work like this line
  }
  
  static class A {
      LocalDate date = LocalDate.now();
  }
  </code></pre>
  
  <p>Yes, you you can supply the <code>Optional::orElse()</code> with a new instance:</p>
  
  <pre><code>LocalDate a_date_field = Optional.ofNullable(a1).orElse(new A()).date;
  </code></pre>
  
  <p>But this is just incorrect. Since <code>a</code> is null, <code>a_date_field</code> should be null as well.</p>
  
  <p>Supplying the field with <code>null</code> obviously won't work:</p>
  
  <pre><code>String afield = Optional.ofNullable(a1).orElse(null).field;
  </code></pre>
  
  <p>This throws NPE.</p>
  
  <p>Is this possible with <code>Optional</code>?</p>