title: Java: avoid checking for null in nested classes (Deep Null checking)
body: <p>Imagine I have a class Family. It contains a List of Person. Each (class) Person contains a (class) Address. Each (class) Address contains a (class) PostalCode.  Any &quot;intermediate&quot; class can be null.</p>
  <p>So, is there a simple way to get to PostalCode without having to check for null in every step? i.e., is there a way to avoid the following daisy chaining code? I know there's not &quot;native&quot; Java solution, but was hoping if anyone knows of a library or something. (checked Commons &amp; Guava and didn't see anything)</p>
  <pre><code>if(family != null) {
      if(family.getPeople() != null) {
          if(family.people.get(0) != null) {
              if(people.get(0).getAddress() != null) {
                  if(people.get(0).getAddress().getPostalCode() != null) {
                      //FINALLY MADE IT TO DO SOMETHING!!!
                  }
              }
          }
      }
  }
  </code></pre>
  <p>No, can't change the structure. It's from a service I don't have control over.</p>
  <p>No, I can't use Groovy and it's handy &quot;Elvis&quot; operator.</p>
  <p>No, I'd prefer not to wait for Java 8 :D</p>
  <p>I can't believe I'm the first dev ever to get sick 'n tired of writing code like this, but I haven't been able to find a solution.</p>