Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Why there are legal?

 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
System.out.println("%b", 123);-why this returns true? Conversion char is boolean type & argument is integer type.

System.out.println("%s", new Long("123"));-Why this works? Conversion char is String type & argument is Wrapper class Long type.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dolly shah:

.... Stuff Deleted....
System.out.println("%s", new Long("123"));-Why this works? Conversion char is String type & argument is Wrapper class Long type.



I am fairly certain the %s functionality will call the toString() method of referenced object.

As for the boolean a wild guess would be to have consistant behavior for the c++ people
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither one of those examples will compile for me as posted.

...println should be printf.

As was stated previously, the %s formatting likely calls the toString() method on the Long wrapper class.

As for the boolean, the %b conversion character returns true for any non-null or non-boolean value. If you replaced the 123 with "A", it still prints true.
[ July 11, 2007: Message edited by: Brad Clarke ]
 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic