Re: question about the toString Method
- From: Lew <lew@xxxxxxxxxxxxx>
- Date: Thu, 27 Dec 2007 19:20:34 -0500
Art Cummings wrote:
You pass a reference to an object, it calls toString() on that reference.
public static void myPrintln( Object obj ) {
String s = obj.toString();
System.out.println( s ); // would actually use a different
// call here...
}
Get it?
The confusing one is how does the compiler know to call toString() when concatenating strings:
String s = "This is a: " + obj;
Answer: the compiler is specially crowbarred to call toString() in that instance.
Thank you everyone, it's a little clearer now.
Ain't the Javadocs a wonderful thing?
--
Lew
.
- References:
- question about the toString Method
- From: Art Cummings
- Re: question about the toString Method
- From: Mark Space
- Re: question about the toString Method
- From: Art Cummings
- question about the toString Method
- Prev by Date: Graphing data in Java
- Next by Date: Re: Graphing data in Java
- Previous by thread: Re: question about the toString Method
- Next by thread: Re: question about the toString Method
- Index(es):