格式化"if"格式的正确方法是什么? Java中带有多行"and"的语句或“或"? [英] What's the proper way to format "if" statements in Java with multiline "ands" or "ors"?

查看:187
本文介绍了格式化"if"格式的正确方法是什么? Java中带有多行"and"的语句或“或"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,"if","and"和"or"是通用搜索参数,我一生都无法在google上找到答案.根据Java标准,以下哪一种是正确的格式?

Apparently "if", "and", and "or" are such generic search parameters that I can't find the answer on google for my life. Which of these is the correct format according to the Java standards?

选项1 :

if (condition1
    && condition2
    && condition3) ...

选项2 :

if (condition1 &&
    condition2 &&
    condition3) ...

推荐答案

Oracle/Sun准则("Java TM编程语言的代码约定")告诉我们在操作员面前先休息一下.他们给出了这个例子.

The Oracle/Sun guidelines ("Code Conventions for the Java TM Programming Language") tell us to break before an operator. And they give this example.

if ((condition1 && condition2)
        || (condition3 && condition4)
        ||!(condition5 && condition6)) {
    doSomethingAboutIt();
} 

我工作过的许多公司都采用Oracle/Sun准则作为自己代码的标准.

Many companies that I've worked for adopt the Oracle/Sun guidelines as the standard for their own code.

请参阅 http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#248

这篇关于格式化"if"格式的正确方法是什么? Java中带有多行"and"的语句或“或"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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