Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8207765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:06:06+00:00 2026-06-07T09:06:06+00:00

I was reading the docs and noticed it. Never imaginated it. The description: This

  • 0

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();.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:06:09+00:00Added an answer on June 7, 2026 at 9:06 am

    Besides filling conventions or using computing resources, what does a .toString() in Java do on a String that using the String itself wouldn’t?

    It means it gives an appropriate result when called polymorphically.

    Why doesn’t it simply inherit the .toString() from class java.lang.Object?

    Because that wouldn’t give the same result, and almost certainly not the desired result.

    Object.toString() is meant to give a reasonably useful string representation of the object. The Object implementation gives information about the type and a value which can be used for crude identity hints (diagnostically useful, but that’s all). That’s clearly not the most useful string representation for a string – the string itself is.

    While I would say that it’s a pity that toString is defined in quite a woolly way (it’s not clear whether the result is meant for machine, developer or user consumption), it feels obvious to me that a String would return itself in the implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading this: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it I came to the conclusion that it is not valid
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
Reading through the javase api docs, I noticed that pretty much all of the
Reading the section Zend_Application_Resource_Modules in the docs here: http://framework.zend.com/manual/1.10/en/zend.application.available-resources.html I noticed this: You can
After reading the docs,I'm doing it this way: ds /c 21 1de2458 But only
Reading the docs on log4net, I noticed that all the std Appenders are labeled
I'm having problems with a NonUniqueObjectException thrown by Hibernate. Reading the docs, and this
I previously posted this question ( Reading Google docs spreadsheet ) and got a
while reading docs of backbone i can't understand how to add model to collection
Reading the docs, I'd expect $(#wrap2).remove(.error) to remove all .error elements from #wrap2 .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.