title: Uses for Optional
body: <p>Having been using Java 8 now for 6+ months or so, I'm pretty happy with the new API changes. One area I'm still not confident in is when to use <code>Optional</code>. I seem to swing between wanting to use it everywhere something may be <code>null</code>, and nowhere at all.</p>
  
  <p>There seem to be a lot of situations when I could use it, and I'm never sure if it adds benefits (readability / null safety) or just causes additional overhead. </p>
  
  <p>So, I have a few examples, and I'd be interested in the community's thoughts on whether <code>Optional</code> is beneficial. </p>
  
  <p>1 - As a public method return type when the method could return <code>null</code>:</p>
  
  <pre><code>public Optional&lt;Foo&gt; findFoo(String id);
  </code></pre>
  
  <p>2 - As a method parameter when the param may be <code>null</code>:</p>
  
  <pre><code>public Foo doSomething(String id, Optional&lt;Bar&gt; barOptional);
  </code></pre>
  
  <p>3 - As an optional member of a bean:</p>
  
  <pre><code>public class Book {
  
    private List&lt;Pages&gt; pages;
    private Optional&lt;Index&gt; index;
  
  }
  </code></pre>
  
  <p>4 - In <code>Collections</code>: </p>
  
  <p>In general I don't think:</p>
  
  <pre><code>List&lt;Optional&lt;Foo&gt;&gt;
  </code></pre>
  
  <p>adds anything - especially since one can use <code>filter()</code> to remove <code>null</code> values etc, but are there any good uses for <code>Optional</code> in collections?</p>
  
  <p>Any cases I've missed?</p>