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.
In php this would be a case of
while ( $returned = myObject->myMethod()->finished )
{
}
if( $returned -> finished == FALSE)
{
...
}
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 )
A while loop checks a conditional. Here's another example that can come handy:
While acceptable in PHP, I guess (I don't code in PHP), it is considered extremely bad form to do an assignment within a conditional in Java. (This is because it is error prone and very hard to spot, the difference being between = and == in the middle of a lot of code. This was a deliberate choice based on years of experience with C and C++.)
As it is, I can't quite follow your code. You say "returnMessage has 2 booleans and a String" but the test, as I understand it in PHP, is
myObject->myMethod()->finished != null
andreturned
gets set to the value offinished
, but then you go and test$returned -> finished
which is the same asmyObject->myMethod()->finished->finished
. Sorry if I misunderstand PHP syntax.The general recommendation in Java would be more along the lines of:
If I misunderstood the PHP, let me know and I'll fix the Java code to match.
We need to see more of your code, but guessing a little I think something like this would work:
this is possible like so
or to be more precise
(returned=myObject.myMethod())
assigns the object returned toreturned
and you can use it like a normal var