Re: question about the toString Method
Art Cummings wrote:
You call
System.out.println(myCourse), which calls
String.valueOf(myCourse), which calls
myCourse.toString(), which returns a String to
String.valueOf(myCourse), which returns the same String to
System.out.println(myCourse), which then calls
System.out.print(theString), which returns to
System.out.println(myCourse), which eventually returns to
You.
--
Eric Sosman
esosman@ieee-dot-org.invalid
Thanks Eric,
I think I follow what you're saying. My Java intermediate course is
starting in a couple of weeks. I'm wondering at what point concepts like
this are introduced. Is this a graduate level understanding? The text by
Tony Gaddis, Starting out with Java, is pretty good, but it drives me crazy
when he leaves out explanations of this type. I'm wondering whether it's
better just to accept what's happening, at my level, or to dig deeper. I
definitely feel that sometimes the ideas have to sit for awhile before they
just seem to gell.
All the data in the quote from Eric is stated in the API documentation
at e.g. http://java.sun.com/j2se/1.5.0/docs/api/index.html. It could be
found from first principles:
1. Note that System is an API class and you don't have to import it, so
select the java.lang package and look for System in its classes.
2. From the System documentation find that System.out is of type
PrintStream and follow the link to the java.io.PrintStream documentation.
3. Look in the PrintStream documentation for println with a general
Object argument.
Carry on like this, until you have found enough data for your current
purposes. It may be worth your while to work through the question,
comparing what you see in the documentation to what Eric wrote.
Fluent use of the API documentation is one of the most important Java
skills. People without that skill are dependent on whatever summaries
appear in books and tutorials they use. People with API documentation
reading skill can use the full range of Java features. Even non-Sun
add-in packages for Java usually have documentation in the same format.
Patricia