The following code:
void someMethod(Object value)
{
String suffix = getSuffix();
if (suffix != null)
value += suffix;
[...]
}
compiles without errors in JDK 8 (using -source 1.6), but fails in JDK 6 with the error message:
Operator '+' cannot be applied to java.lang.Object and java.lang.String
While I do understand what the error is about, why does this compile with JDK 8? Is this documented anywhere?
value = value + suffix
is completely legal regardless of the type of value. So it seems to mevalue += suffix
should be legal too. – Dickie