Hello All,
Please go throug the code below :
I have a basic question on boxing and unboxing of the wrapper classes. From the above code,
I understand that from line#1 b1==b2 resulted false, as b2 is pointing to a completely new object on heap and b1 is pointing to a reference (from boolean pool, just like
string pool) to another diferent object on the heap.
On line # 2, b1==b3 , resulted true, because I guess b3 is autoboxed to a Boolean object and both are pointing to a same boolean reference from boolean pool. Or considering other way b1 might be unboxed becoming a boolean identifier and now both b1 and b3 are booleans not Booleans. So since both holding same bit
pattern, resulted true
My question is regarding line # 3, I believed that this should result in false, assuming b3 getting autoboxed to Boolean object, it would point to an entirely a different object (again some reference from boolean pool), from that one being pointed by b2. But the answer is true. Or did b2 got Unboxed itself
How could the line # 3 resulted in true? What actually happened here? Did unboxing happened here or autoboxing? Which one would take priority? How to decide which one is going to happen?
Please clarify me on this. I have the same query on the Integer operation also, given in the code and believe the same postulate holds good for other wrapper classes.