函数返回Java中的书写风格 [英] Function Return writing style in Java

查看:109
本文介绍了函数返回Java中的书写风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是:

String function() { return someString; }

有什么不同吗?

String function() { return(someString); }

我感兴趣的回报。我看到第二种风格不那么频繁了,是不是约定或是括号中的返回实际上做了哪些不同的事情?

Its the return I'm interested in. I see the 2nd style less frequently, is it just convention or is the return in parenthesis actually doing something different?

推荐答案

不,包装返回之间没有任何功能差异括号中的值与否。

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

根据 Java编码公约(第7.3节),你应该坚持

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

return expression;

除非paretheses更明确:

unless the paretheses makes it more clear:

7.3 return语句

带有值的return语句不应使用括号,除非它们以某种方式使返回值更明显。

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.

示例:
$
返回;

return myDisk.size();

return insert(root,data);

return(size?size:defaultSize);

这篇关于函数返回Java中的书写风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆