File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unboxing weirdness

 
Tom McCann
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tom McCann
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much.

Tom
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic