title: Java best style for return statement - inside or outside if condition?
body: <p>Is there a better way to write the code below? I'm checking if an object is null, returning false if it is, otherwise I check another variable and choose what to do based on that.</p>
  
  <pre><code>private boolean myFunction(MyObjectType myObject) {
    if (myObject == null) {
      return false;
    } else if (myInstanceVariable.myMethod()) {
      // Do something then return
      System.out.println(myObject.getSomeValue());
      return true;
    } else {
      return false;
    }
  }
  </code></pre>
  
  <p>Is it better to have the final else statement or move the <code>return false</code> (and any other code that I may have put before it inside the final <code>else { }</code> block) outside the if statement? I could see it being safer (and fewer lines of code) to move it outside so the function is 100% guaranteed to return. Could it depend on how the compiler behaves?</p>
  
  <pre><code>private boolean myFunction(MyObjectType myObject) {
    if (myObject == null) {
      ...
    } else if (myVariable.myMethod()) {
      ...
    }
    return false;
  }
  </code></pre>