Page 1 of 1

About Question enthuware.ocajp.i.v8.2.1422 :

Posted: Sat May 28, 2016 8:40 am
by vsudakov
Hello.

From explanation:
1. When one of the operands of the + operator is a String and other is an object (other than String), toString method is called on the other operand and then both the Strings are concatenated to produce the result of the operation.
Is it true? I thought that String.valueOf(x) method is called on operand instead of just toString... That's why concatenation operation is null-safe.

Re: About Question enthuware.ocajp.i.v8.2.1422 :

Posted: Sun May 29, 2016 12:06 am
by admin
It is true. String.valueOf internally calls toString on the object. The actual string is therefore produced by the toString method of the class of that object.