Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
    Bookmark Topic Watch Topic
  • New Topic

toString method class - question

 
Abid Ramay
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi there

how do you read Java API documentation? e.g. below toString() method class .. how do i read this information ?


toString

public String toString()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())


Returns:
a string representation of the object.


thanks for you help.
 
Campbell Ritchie
Sheriff
Posts: 48394
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
The API documentation is not written so as to be easy for beginners to read, but that particular example is clear. What are you having difficulty with?
 
Joel Christophel
Ranch Hand
Posts: 250
1
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Report post to moderator
Abid Ramay wrote:
public String toString()


public means that the method is visible and can be called from other objects of other types. String tells you that the method's return type (output) is a String. The empty parenthesis in toString() tell you that you don't have to pass in anything to the method.

Abid Ramay wrote:
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object.


This is the summary of the method's function. This also tells you that the toString() can be used on any object (since it is defined in the Object class).

The best way to find out exactly how a method works, however, is to try it out.
Try something like:



And try different things. For example, using the toString method on objects like Integer or Boolean simply returns their values as a String.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12085
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
the above is

name of the method

the method's signiature

a description of what it does.

what it returns.

Which part doesn't make sense?
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic