在Java while循环条件中分配变量? [英] Assign variable in Java while-loop conditional?
问题描述
我有一个方法可以进行大量的检查和计算,并返回一个自定义类returnMessage。 returnMessage有2个布尔值和一个String。我想要做的是在我的主类的while循环中运行此方法,并在while循环最后一次终止后访问returnMessage对象。
I have a method that does a lot of checking and computation and returns a custom class, returnMessage. returnMessage has 2 booleans and a String. What I want to do is run this method in a while loop from my main class and have access to the returnMessage object after the while loop terminates for the last time.
在php中,这将是
while ( $returned = myObject->myMethod()->finished )
{
}
if( $returned -> finished == FALSE)
{
...
}
但是尝试像这样分配在java中给我一个布尔预期的错误(上面可能有php错误,已经晚了:D)
However trying to assign like this gives me a boolean expected error in java (there might be php errors in the above, it's late :D )
推荐答案
我们需要看到更多你的代码,但猜一点我觉得这样的事情会起作用:
We need to see more of your code, but guessing a little I think something like this would work:
ReturnMessage returned;
while (!(returned = myObject.myMethod()).finished) {
}
if (!returned.finished) {
}
这篇关于在Java while循环条件中分配变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!