【发布时间】:2011-09-23 06:30:15
【问题描述】:
(代码约定文档:http://www.oracle.com/technetwork/java/codeconventions-142311.html#449)
我一直把 if-else 语句写成:
if(condition) {
statements;
} else {
statements;
}
然而,在 Java 代码约定文档中,它说要这样写:
if (
condition) {
statements;
} else {
statements;
}
而且,我总是写这样的陈述:
for(initialization;condition;update) {
statements;
}
但是编码约定说:
for (
initialization;
condition;
update) {
statements;
}
缩进和间距对我来说似乎是不必要的麻烦。哪个是正确/更好的方法,为什么?
【问题讨论】:
-
即我应该遵守约定吗?
-
约定页面好像有问题。改为阅读 pdf:java.sun.com/docs/codeconv/CodeConventions.pdf
标签: java for-loop conventions if-statement