title: Optional vs if/else-if performance java 8
body: <p>Hello i have two samples of code</p>
  
  <p>if/else if/else statements</p>
  
  <pre class="lang-java prettyprint-override"><code>private Object getObj(message) {
          if (message.getA() != null)
              return message.getA();
          else if (message.getB() != null)
              return message.getB();
          else if (message.getC() != null)
              return message.getC();
          else return null;
  }
  </code></pre>
  
  <p>Optional statements</p>
  
  <pre class="lang-java prettyprint-override"><code>private Optional&lt;Object&gt; wrap(Object o){
      return Optional.ofNullable(o);
  }
  
  private Object getObj(message) {
      return  wrap(message.getA())
              .orElseGet(() -&gt; wrap(message.getB())
              .orElseGet(() -&gt; wrap(message.getC())
              .orElse(null)));
  }
  </code></pre>
  
  <p>So my question is how these two compare in terms of performance (i have about 15-20 if-else statements on actual code)?</p>
  
  <p>Is it worth refactoring the code readability vs performance or is a misusage of optionals?</p>
  
  <p>Also what is the performance penalty in case the if/else-if statements grown to 100+?</p>
  
  <p>Thanks in advance</p>