【发布时间】:2012-11-14 17:41:00
【问题描述】:
假设我有一个布尔方法,它使用 if 语句来检查返回类型应该是 true 还是 false:
public boolean isValid() {
boolean check;
int number = 5;
if (number > 4){
check = true;
} else {
check = false;
}
return check;
现在,我想在 不同 方法中将此方法用作 if 语句的参数:
if(isValid == true) // <-- this is where I'm not sure
//stop and go back to the beginning of the program
else
//continue on with the program
所以基本上我要问的是,我如何检查 if 语句的参数中的布尔方法的返回类型是什么?非常感谢您的回答。
【问题讨论】:
-
怎么样 -
if (ifValid())。如果您注意到它,您的方法将始终返回true。 -
是的,你的方向是正确的...... :)
-
有点离题,但偶然发现这个问题让我想起了我作为一名程序员已经走了多远。很棒的感觉。
标签: java methods if-statement boolean