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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
vsudakov
Posts: 4
Joined: Sat May 28, 2016 8:31 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], tequilaa and 8 guests