Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
format() question
Tamara Lopez
Ranch Hand
Posts: 63
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 63
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 83
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
because it implicitly invoke the new object`s toString{}
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Am I just stupid?
Cast from an Object to a primitive long
convert a String to Long
Lock/unlock please comment my code
[rated r]ugliness unlimited
More...