In Java given this:
String a = "str";
CharSequence b = "charseq";
you can write
b = b + a;
but cannot write (gives a compiler error)
b += a;
The error is
incompatible types
found : java.lang.CharSequence
required: java.lang.String
Now in JLS Second Edition this was explainable by this line in 15.26.2 Compound Assignment Operators:
All compound assignment operators require both operands to be of primitive type, except for +=, which allows the right-hand operand to be of any type if the left-hand operand is of type String.
But in JLS Third Edition this comment disappeared, the only thing that is said about compound operator is at 15.26.2 Compound Assignment Operators:
A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.
which doesn’t seem to work (see above).
So my question is – what exactly is the relationship between javac and JLS and is this particular example an error in javac or an error in JLS?
compiler error is a bug in your version javac. As pointed in prior answer this bug is fixed in Java 7.
See eg Bug ID 7058838 at Sun bug database:
Not a Defect
For a background, see also old Bug Id 4741726
java:compiler
7(b25) – as far as I understand, this means fixed in build 25 of Java 7