• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wrapper and == question

 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I don't understand why


prints true.

and

doesn't.
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 ?

thanks!
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 159
C++ Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!


regards,
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic