title: How to use Optional to check null values in java 8?
body: <p>I have a class containing nested and inner classes. And in some program, i am check for the null values of the object using equal operator in the legacy java way. The following is my code snippet:</p>
  
  <pre><code>class Outer {
      Nested nested;
      Nested getNested() {
          return nested;
      }
  }
  class Nested {
      Inner inner;
      Inner getInner() {
          return inner;
      }
  }
  class Inner {
      String foo;
      String getFoo() {
          return foo;
      }
  }
  </code></pre>
  
  <p>And here is how i am doing the null checks on the reference variables:</p>
  
  <pre><code>Outer outer = new Outer();
  if (outer != null &amp;&amp; outer.nested != null &amp;&amp; outer.nested.inner != null) {
      System.out.println(outer.nested.inner.foo);
  }
  </code></pre>
  
  <p>I know this can also be done using the Optional class of java 8, but i am not getting a way for doing the same above particular scenario.
  Any suggestion?</p>