• 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

Boolean instead of boolean

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Explain please why



compiles and works fine (prints "It's work!").
[ January 17, 2006: Message edited by: Dmitryi Neverov ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason why the code works is because of Autoboxing feature of java 5.0.

new Boolean("TRuE") - creates a new Boolean object and when used with if condition, autoboxing takes place and the object is automatically converted to a primitive boolean value, which in this case is true and hence the following printf statement is executed.


Ranchers correct me if i am wrong.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does this compile ? I don't think it will with Java 1.4 or less.
Are you using Java 1.5 ?
In this case, the Boolean class will be unboxed to a boolean primitive, which value is set to "true".
 
Dmitryi Neverov
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx.
Yes, I'm using 1.5 jdk, but I'm preparing for 310-035, and didn't know about this behavior of 1.5 jdk.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're preparing for 310-035, you'd better use JDK1.4 then
Good luck.
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its legal.

true if the string argument is not null and is equal, ignoring case, to the string "true".

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Satou, you'd better off using JDK 1.4. Tiger (1.5 or 5.0) is a new release that has major changes introduced. In 1.5 some things would give warnings if used the 1.4 way.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Prash is right. This will work only with JDK 1.5, wont compile with 1.4 and it works coz of auto-unboxing feature
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic