aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Wrappers question 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 "Wrappers question" Watch "Wrappers question" New topic
Author

Wrappers question

Natallia Bahlai
Greenhorn

Joined: Jan 14, 2009
Posts: 11

Why b2 == b3 results true while b1 == b2 return false?

Thanks in advance.
Natallia Bahlai
Greenhorn

Joined: Jan 14, 2009
Posts: 11
The second question is


Why i1 == i3 returns false?
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489



Result :
false
true
true


b1==b2 results false because it checks the same object in memory, especially checks the same object's id in memory..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Natallia Bahlai
Greenhorn

Joined: Jan 14, 2009
Posts: 11
And what happens when I compare b2 == b3, boxing or unboxing occurs?

Thanks.
Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107
b2 will unbox from Boolean to boolean, and compare unboxed value with value of b3
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Natallia Bahlai wrote:And what happens when I compare b2 == b3, boxing or unboxing occurs?
.


i think it is done implicitly by compiler, because either boxing or unboxing occurs will give the same result...

Result : true


Result : true
Purvesh Maheshwari
Greenhorn

Joined: Dec 30, 2009
Posts: 2
Natallia Bahlai wrote:The second question is

Why i1 == i3 returns false?




When AUTO-Boxing done at line Integer i3=i2,new object implicitly generated and the int value is assigned to new object.when you trying to compare two different object using == then it will return false.

Also AUTO-Unboxing will be done while comparing one primitive type with object of respective wrapper class.
But NO AUTO (UNBOXING OR BOXING) operation happen while comparing two object using == operate.

Hope this will help you Natallia.
Natallia Bahlai
Greenhorn

Joined: Jan 14, 2009
Posts: 11
Thanks for clarifications!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrappers question
 
Similar Threads
Boolean
Boolean == Vs .equals()
Boxing query
Boolean ==
Boolean doubt