aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes regarding Wrapper's unboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "regarding Wrapper Watch "regarding Wrapper New topic
Author

regarding Wrapper's unboxing

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
As we know that-- True,TRUE are wrapper Boolean values.


First see code:
boolean b=TRUE;//line 1

Boolean b2=true; //line 2

Now my question is that as in line 2, true value (i.e. primitive value) boxed into wrapper value and then assign to wrapper variable b2.But why not in line 1,True value (that is wrapper value) unboxed to primitive value and then assign to primitive variable.


SCJP 5.0(75%), SCWCD 5.0(88%)
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
You can use the Boolean object but intead you have use it with refence of class as-:

boolean b=Boolean.TRUE; instead of boolean b=TRUE;

Now it will work out fine
Dean Jones
Ranch Hand

Joined: Dec 29, 2007
Posts: 129
boolean b=True, or boolean b=True does not compile as it they are not recogninized by the compiler.
You can try,
Boolean b2=new Boolean("TRUE");
Boolean b3=new Boolean("True");
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: regarding Wrapper's unboxing