如何从另一个方法中捕获一个方法的布尔返回值并执行一些操作?

时间:2018-12-31 04:40:11

标签: java spring return

我在同一个类中有两个方法。

public Boolean pinValidation(Obj 1, Obj 2){

// Here i have to return Boolean true or false
 boolean status = false;
 /..... Some Code segments goes here .. 
 return true;
}

public Payment checkPayment(Obj 1, Obj2){
 pinValidation();

// Here if the return value of first method true
 if(status == true){
    //set of instructions
   }
}

我想如何捕捉上述返回布尔值并执行该操作? 有帮助吗?

2 个答案:

答案 0 :(得分:4)

您可以执行以下操作:

boolean status = pinValidation();

或者您可以通过以下方式简化操作:

if (pinValidation()) {
    //set of instructions
}

注意:在任何地方都使用boolean。无需混合使用booleanBoolean

答案 1 :(得分:0)

首先,您需要了解如何管理条件,所以让我添加一些有关条件的代码:

 if (true) { //if the  condition is true, the code below will be executed 
   // code to execute here
 } 

然后,您无需评估someBooleanValue == true,只需调用它即可。

 if (pinValidation()) {
   // code to execute here
 } 

第二,您需要了解布尔(一种可以帮助您使用某些方法的对象)与布尔(原始类型)之间的区别并节省大量内存,然后您就可以根据自己的问题使用更好的了。

相关问题