Java – = and =

I've been misplaced = many times, I think I've always forgotten, because I don't know the difference between the two. Only the one gives me the value I expect, and the other doesn't

Why?

Solution

A = B is the short hand of a = a B (although note that expression a will only be evaluated once.)

A = B is a = (b), that is, the unary of B is assigned to a

example:

int a = 15;
int b = -5;

a += b; // a is Now 10
a =+ b; // a is Now -5
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>