What is the best practice of using return keyword?

Posted by Artic on Stack Overflow See other posts from Stack Overflow or by Artic
Published on 2010-03-18T09:17:31Z Indexed on 2010/03/18 9:21 UTC
Read the original article Hit count: 302

Filed under:
|

What is the best practice of using return keyword? If i need to return something from method which pattern is better to use?

public boolean method(){
    if (case1){
       return true;
    }
    if (case 2){
       return false;
    }
    return false;
}

or

public boolean method(){
    boolean result = false;
    if (case1){
       result = true;
    }
    if (case 2){
       result = false;
    }
    return result;
}

© Stack Overflow or respective owner

Related posts about java

Related posts about best-practices