title: Casting type inside Optional
body: <p>I have the following:</p>
  
  <pre><code>class Foo implements Inter {
      void doSomething();
  }
  
  Optional&lt;Inter&gt; getPossible() {
      Optional&lt;Foo&gt; possible = ...;
      possible.ifPresent(Foo::doSomething);
      return possible.map(f -&gt; f);
  }
  </code></pre>
  
  <p><code>getPossible</code> needs to return an <code>Optional&lt;Inter&gt;</code> because it's overriding a superclass's implementation.</p>
  
  <p>That map at the end of the method is purely to convert the type. Is there a more elegant option?</p>