Re: question about the toString Method
- From: "Art Cummings" <aikiart7@xxxxxxxxx>
- Date: Thu, 27 Dec 2007 16:27:59 -0500
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.
Art
.
- Follow-Ups:
- Re: question about the toString Method
- From: Lew
- Re: question about the toString Method
- References:
- question about the toString Method
- From: Art Cummings
- Re: question about the toString Method
- From: Mark Space
- question about the toString Method
- Prev by Date: Re: question about the toString Method
- Next by Date: How To retrieve the full user name, in Vista??
- Previous by thread: Re: question about the toString Method
- Next by thread: Re: question about the toString Method
- Index(es):