int a = 1L; won’t compile and int b = 0; b += 1L; compiles fine. Why ?


When += is used, that’s a compound statement and the compiler internally casts it. Whereas in the first case, the compiler straightaway shouts at you since it is a direct statement.

Compiler behavior and statement types can be confusing, so questions like this will test a candidate's grasp of these concepts.

0 answers