This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wrapper and == question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wrapper and == question" Watch "wrapper and == question" New topic

wrapper and == question

Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159


I don't understand why

prints true.


I thought when 'new' is involved you are actually bypassing the cache of the classes. Which seems to be so in the second example, but this doesn't seem to be the case in the first example (where there is a new involved))

Could someone explain this ?


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The reason is that the return type of Boolean.parseBoolean is a primitive boolean.

When == is applied to a boolean and a Boolean, then the Boolean is unboxed and == is boolean equality.
Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

oops,that was actually something I should have been able to see myself..
I guess I was blinded by the 'new' and got confused.

Thanks a lot!

I agree. Here's the link:
subject: wrapper and == question
Similar Threads
Boolean values
Boolean unboxing.
JAVA is not 100% casesensitive how???
Boolean ==
Doubt:Sequence of the output