title: Java 8 optional add return result only if optional.isPresent
body: <p>I have a piece of code where an interface has an Optional return method and some of the classes that implement it to return something, other don't.</p>
  
  <p>In an effort to embrace this brilliant "null killer", here is what I have tried:</p>
  
  <pre><code>public interface Gun {
      public Optional&lt;Bullet&gt; shoot();
  }
  
  public class Pistol implements Gun{
      @Override
      public Optional&lt;Bullet&gt; shoot(){
          return Optional.of(this.magazine.remove(0)); 
      }//never mind the check of magazine content
  }
  
  public class Bow implements Gun{
      @Override
      public Optional&lt;Bullet&gt; shoot(){
          quill--;
          return Optional.empty();
      }
  }
  
  public class BallisticGelPuddy{
      private Gun[] guns = new Gun[]{new Pistol(),new Bow()};
      private List&lt;Bullet&gt; bullets = new ArrayList&lt;&gt;();
      public void collectBullets(){
          //here is the problem
          for(Gun gun : guns)
              gun.shoot.ifPresent(bullets.add( &lt;the return I got with the method&gt;)
  }}
  </code></pre>
  
  <p>I apologise for how silly this example is.<br>
  How can I check the return I just got and add it only if present, using optional?</p>
  
  <p>P.S. is there any real usefulness to Optional which is if(X != null) couldn't do?</p>