This is behavior specified in the Java API's String.valueOf(Object)
method. When you do concatenation, valueOf
is used to get the String
representation. There is a special case if the Object is null
, in which case the string "null"
is used.
public static String valueOf(Object obj)
Returns the string representation of the Object argument.
Parameters: obj - an Object.
Returns:
if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned.