This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Wrapper Class equlas() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Wrapper Class equlas()" Watch "Wrapper Class equlas()" New topic
Author

Wrapper Class equlas()

Shiva Mohan
Ranch Hand

Joined: Jan 05, 2006
Posts: 465



b1 and b2 references having same object but having different value.I thought it won�t display anything.But it displayed We are Equal.It is quite confusing for me.please someone clarify how it gives that output.
Sam Codean
Ranch Hand

Joined: Feb 26, 2006
Posts: 194
The wrapper classes override the equals() method to do the value comparison and not the object comparison. Here the values of both instances of Boolean are false and hence it will compare true.
BTW passing a null in a constructor by default calls the String Constructor if any.
Hope that helps!!


-Sam Codean<br />SCJP 1.4 (98%)<br />SCJD 5.0 (87.5%)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24057
    
  13

All Boolean objects represent either "true" or "false". It just so happens that they decided that "new Boolean(null)" should return a "false" one. All "false" Booleans are equal, as are all "true" ones.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wrapper Class equlas()
 
Similar Threads
Something about auto-boxing/unboxing in SE5
Boolean == Vs .equals()
Boolean
how to compile java source code with assertion ?
Explain me this Programm