This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Unboxing weirdness Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unboxing weirdness" Watch "Unboxing weirdness" New topic
Author

Unboxing weirdness

Tom McCann
Ranch Hand

Joined: Aug 27, 2005
Posts: 31
Can anyone explain why the following code compiles and runs successfully ?



A Long is not a string. The fact that it was created from a string strikes me as irrelevant.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

If you read the (admittedly quite long and involved!) javadoc for java.util.Formatter, which is used to implement the format() method, it explains precisely how %s and all other conversions are handled. "%s" is what they call a general conversion. General conversions can be applied to any data type. The Javadoc says about %s that


If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().


Unboxing is not involved here.
[ March 04, 2006: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Tom McCann
Ranch Hand

Joined: Aug 27, 2005
Posts: 31
Thanks very much.

Tom
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unboxing weirdness