types - Difference between a+=b and a=a+b in Java -



types - Difference between a+=b and a=a+b in Java -

this question has reply here:

difference between += 10 , = + 10 in java? 5 answers

i've been told there differences between a+=b; , a=a+b; can result in 1 of beingness legal depending on type declerations.

does have illustration of this?

there no difference, there subtle difference.

the arithmetic assignment operators implicit cast. e.g.

byte = 1; int b = 2; += b; // compiles = + b; // doesn't compile byte + int = int = (byte) (a + b); // compiles same +=

for more weird examples.

int = 5; += 1.5f; // == 6 char ch = '0'; // (char) 49 ch *= 1.1; // ch = '4'; long l = integer.max_value; l += 0.0f; // = (long ) ((long ) l + 0.0f) // == integer.max_value + 1l; wtf!? // l no longer integer.max_value due rounding error.

java types operators

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -