What is the preferred way to write boolean expressions in Java

前端 未结 9 2070
灰色年华
灰色年华 2021-01-18 05:03

I have always written my boolean expressions like this:

if (!isValid) {
  // code
}

But my new employer insists on the following style:

9条回答
  •  没有蜡笔的小新
    2021-01-18 05:24

    You are evaluating the variable, not false so the latter is not correct from a readability perspective. So I would personally stick with the first option.

提交回复
热议问题