title: Java: if-return-if-return vs if-return-elseif-return
body: <p>Asked an <a href="https://stackoverflow.com/q/5661936/39321">unrelated question</a> where I had code like this:</p>
  
  <pre><code>public boolean equals(Object obj)
  {
      if (this == obj)
          return true;
  
      if (obj == null)
          return false;
  
      if (getClass() != obj.getClass())
          return false;
  
      // Check property values
  }
  </code></pre>
  
  <p>I got a comment which claimed that this was not optimal, and that it instead (if I understood correctly) should do this:</p>
  
  <pre><code>public boolean equals(Object obj)
  {
      if (this == obj)
          return true;
  
      else if (obj == null)
          return false;
  
      else if (getClass() != obj.getClass())
          return false;
  
      // Check property values
  }
  </code></pre>
  
  <p>Because of the return statements, I can't really see why any of them should be more efficient or faster than the other. Given a certain object, both methods would have to do an equal number of checks as far as I can see. And because of the return statements, no extra code would run in any of them.</p>
  
  <p>Am I missing something here? Is there something to it? Are there some compiler optimizations or something going on or whatever?</p>
  
  <p><em>I know this is micro optimization and I will most likely stick with the first either way, since I think it looks cleaner with all the ifs on the same position. But I can't help it; I'm curious!</em></p>