If you have an object of type
String, you can’t invoke
toString() on it, because it already is a
One cannot invoke toString() on a String
One can invoke toString() on a String
CorrectionHere is what's right.
Here is what's right.
toString() method is declared in class
java.lang.Object, and thus inherited by
java.lang.String (a subclass of
java.lang.Object). As such, it’s perfectly legal to invoke
toString() on a
String object. The result will be the object itself, so the invocation is really unnecessary:
String s = ...; assert s.toString() == s;