Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Boolean instead of boolean

 
Dmitryi Neverov
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explain please why



compiles and works fine (prints "It's work!").
[ January 17, 2006: Message edited by: Dmitryi Neverov ]
 
Prash Gali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're preparing for 310-035, you'd better use JDK1.4 then
Good luck.
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its legal.
true if the string argument is not null and is equal, ignoring case, to the string "true".
 
Alex Khvatov
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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.
 
Rupak Khurana
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic