When making an assignment, the value assigned is considered the "result" or "return value" of the expression. It's subtle and maybe not clear because your example is something that is rarely done.
int i = 5;
int j = (i = 6);
At this point in the code, both
j are equal to 6. We assigned i to the value 6 and then captured the return value of the expression, which is the value which was transferred, which is 6.
Personally, I would avoid this because it can be very confusing and easy to introduce bugs. Especially in a System.out.println or any call that is expected to not change the state. It violates the principle of least astonishment.
Ever wonder why programming classes teach you to always use a double-equals (
==) in an if statement? Ever noticed that with a single equal sign, it may still work? This is why. The process of evaluating a condition is changing the condition, creating a truism or falsism. The number of software defects caused by
if (x = y).....
Many programmers (I have not picked up the habit yet, but probably ought to) prefer to write if statements with the constant on the left side like
if (5 == x) instead of
if (x == 5) so that if they accidentally use a single equal sign, the compiler won't allow it.
To take this to your code example, you are right, the expression is "returning" a value.
System.out.println(fruit="Orange"); //prints orange
When the JVM runs this code, one instruction at a time, it sees 3 instructions in this order:
String someInternalStackVariableYouDontSee = (fruit = "Orange");