I was reading the docs and noticed it. Never imaginated it. The description:
This object (which is already a string!) is itself returned.
Besides filling conventions or using computing resources, what does a .toString()
in Java do on a String
that using the String
itself wouldn't? Why doesn't it simply inherit the .toString()
from class java.lang.Object
?
EDIT:
I understand that in situations of polymorphism an own toString()
method has to exist since it overrode its parent's toString()
. What I want to know in the first question is if there is any situation where you'll get something different between using stringVariable
/"String value"
and using stringVariable.toString()
/"String value".toString()
.
Ex. gr.: An output operation like System.out.println(stringVariable.toString());
or a value assignment like stringVariable = "String value".toString();
.