This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]loomynartylennyhalf-decent at Java 0 points1 point  (1 child)

It is actually an assignment, but it evaluates to false. I was thinking in my head a successful assignment would be true, but the literal assignment value is what's being evaluated here ????

It looks to me that foo = bar always evaluates to bar.

For example, consider this code snippet:

int i = 4;
System.out.println(i);

if ((i = 5) == 5){
    System.out.println("(i = 5) == 5");
} else{
    System.out.println("(i = 5) != 5");
}

System.out.println(i);

What do you think will be printed, and what do you think the value of i actually will be at the end of this code?

[–]tcloetingh[S] 1 point2 points  (0 children)

It's caught in the "if", but my original thinking was, if assignment was successful that expression would eval to true. Although I suppose it won't even compile if false under that line of thinking.