Java 没有 else 语句的 if 语句是不是很糟糕?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21081558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:26:20  来源:igfitidea点击:

Is it bad to have if statements without else statements?

javaif-statement

提问by Lorenzo_g

I was just curious to know if its a bad thing to have an if(){} construct without an else statement in java.

我只是想知道在 java 中使用 if(){} 构造而没有 else 语句是否是一件坏事。

回答by XWaveX

No of course not. There are several times when you only need an if statement without a corresponding else.

不,当然不是。有几次您只需要一个 if 语句而没有相应的 else 语句。