http://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.11:
If the reference is null, it is converted to the string "null" (four ASCII characters n, u, l, l).
So yes, it will not throw a NPE (as long as the +
resolves to a string concatentation, rather than an arithmetic operation)
EDIT:
Actually, looking at this carefully, the behaviour isn't technically defined.
String conversion only applies to an argument to +
that is not a string. If both arguments are a string, then no conversion is done (so 5.1.11 does not apply).
We then move onto http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.18.1, which only specifies the following:
...The characters of the left-hand operand precede the characters of the right-hand operand in the newly created string.
Note there's no reference to null
s.
So I don't think the behaviour of (String)null + (String)null
is technically defined...