Function Return writing style in Java

后端 未结 5 1028
眼角桃花
眼角桃花 2020-12-06 16:08

Is this :

String function() { return someString; }

Any different than this ?

String function() { return(someString); }
         


        
5条回答
  •  抹茶落季
    2020-12-06 17:11

    No, there is no functional difference at all between wrapping the return value in parentheses or not.

    According to the Java Coding Convention (section 7.3), you should stick with

    return expression;
    

    unless the paretheses makes it more clear:

    7.3 return Statements
    A return statement with a value should not use parentheses unless they make the return value more obvious in some way.

    Example:
    return;
    return myDisk.size();
    return insert(root, data);
    return (size ? size : defaultSize);

提交回复
热议问题