I was doing some tests and realized that using one or the other, the result ends up being the same. I made this code to exemplify:
public class ParseToStringTest {
public static void main(String[] args) {
new ParseToStringTest().parseTest();
}
public void parseTest() {
SomeObj o = new SomeObj();
System.out.println(o.toString());
System.out.println(String.valueOf(o));
}
class SomeObj {}
}
Running on ideone , the result I got was:
Ideone$SomeObj@677327b6
Ideone$SomeObj@677327b6
That is, the result was identical.
Would it make any difference between using String#valueOf()
or Object#toString()
to display a representation of the object in the form of a String?