File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes format() question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "format() question" Watch "format() question" New topic
Author

format() question

Tamara Lopez
Ranch Hand

Joined: Feb 21, 2006
Posts: 63
As part of Q9 Chapter 6(p503) in K&B:
Will this compile:
System.out.format("%s",new Long("123"));

The answer is yes.

But new Long would return a Long - which is not a String. But it does work. Why??
Thanks
Oscar Gonzalez
Ranch Hand

Joined: Mar 28, 2006
Posts: 63
The Long.toString() method is called to make the cast. The compiler says: "I know you want to convert the Long to a String and do it automaticaly"

Changchun Wang
Ranch Hand

Joined: Feb 15, 2006
Posts: 83
because it implicitly invoke the new object`s toString{}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: format() question