• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper Class equlas()

 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic