これを与えられたJavaでは:
String a = "str";
CharSequence b = "charseq";
あなたは書ける
b = b + a;
書き込みはできません (コンパイラ エラーが発生します)。
b += a;
エラーは
incompatible types
found : java.lang.CharSequence
required: java.lang.String
現在、JLS Second Edition では、これは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.
しかし、JLS 第 3 版では、このコメントは消えました。複合演算子について述べられていることは、15.26.2 複合代入演算子だけです。
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.
うまくいかないようです(上記を参照)。
だから私の質問は - javac と JLS の関係は正確には何ですか?この特定の例は javac のエラーですか、それとも JLS のエラーですか?