Possible Duplicate:
Java += operator
In Java, this is not valid (doesn't compile), as expected:
long lng = 0xffffffffffffL;
int i;
i = 5 + lng; //"error: possible loss of magnitude"
But this is perfectly fine (?!)
long lng = 0xffffffffffffL;
int i = 5;
i += lng; //compiles just fine
This is obviously a narrowing operation, that can possibly exceed the int
range. So why doesn't the compiler complain?