posted 21 years ago
a = a + 2; // compile fail - possible loss
- This would fail to compile because the result is promoted to int, and assigning an int to a char would fail without an implied cast.
a += 2; // compile and run ok
- This is a compound assignment operation, and in this kind of operation, an implicit cast is made to the result(see JLS 15.26.2). So this operation is equivalent to:
a=(char)(a+2);