In Java, I really wonder is there a difference between using a += b; or a = a + b; . Which one should I use principally? I know that first one is something like shortcut but does the compiler get those two indications differently?
In Java, I really wonder is there a difference between using a += b;
Share
See the Java language specification, 15.26.2 Compound assignment operators
To quote the relevant parts:
So it is more than syntactic sugar, as
compiles, where
gives you a compile error, as was discussed here on StackOverflow quite recently