在 Java while 循环条件中分配变量? [英] Assign variable in Java while-loop conditional?

查看:31
本文介绍了在 Java while 循环条件中分配变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法可以进行大量检查和计算并返回一个自定义类 returnMessage.returnMessage 有 2 个布尔值和一个字符串.我想要做的是在我的主类的 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 中,这将是

In php this would be a case of

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆