I tried to understand how exactly the return value of assignment operation works. followed by this post "Java returns the assigned value".
boolean b1 = false, b2 = false;
if (b2 = b1 == false) {
System.out.println("true");
} else {
System.out.println("false");
}
b2 is true because of (b1 == false) return true, then the return of b2 assignment b2 = true
Or is it because of some other reason?
You've got it right. The operator precedence rules make sure that first the == operator is evaluated. That's b1==false, yielding true. After that, the assigned is executed, setting b2 to true. Finally, the assignment operator returns the value as b2, which is evaluated by the if statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With