【问题标题】:how to put a boolean method from another class in an if statement如何将另一个类的布尔方法放在 if 语句中
【发布时间】:2016-04-19 20:51:55
【问题描述】:

对不起,如果这个问题太简单了,但简单地说,这样做的正确方法是什么:

OtherClass ClassObj = new OtherClass();

if(ClassObj.booleanMethod().equals(true)){
    do a thing
}

我知道这是一个基本的逻辑错误和误解,但到目前为止我还没有找到答案。

【问题讨论】:

  • if(Class.booleanMethod()){//if ture }else{//如果值为false}
  • 对象声明应以小写字母开头,不应命名为“类”
  • 是的 UUIIUI 我知道我这样做只是为了展示我在示例中尝试做的事情。

标签: java if-statement methods boolean


【解决方案1】:

你必须使用

if(classObj.booleanMethod()){
    do a thing if its true
}else{
    do a thing if its false
}

【讨论】:

  • 那么我如何获得 if 来检查它的真假?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-05-25
  • 2013-03-26
  • 1970-01-01
  • 2013-03-20
  • 1970-01-01
  • 2013-03-03
相关资源
最近更新 更多