Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equals() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "equals()" Watch "equals()" New topic
Author

equals()

sandhi mridul
Ranch Hand

Joined: Jan 25, 2008
Posts: 71
Hi,



output: false
true
false
true

As per rule a.equals(null) should always be false for any non-null refrence of a.
Then why at line 2 and line 4 the output is true?

please help me with this.

Thanks
Sandhi
Irina Goble
Ranch Hand

Joined: May 09, 2004
Posts: 91

creates a Boolean object with value false.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by sandhi mridul:
...As per rule a.equals(null) should always be false for any non-null refrence of a...

You do not have equals(null) in the above code, because new Boolean(null) creates a Boolean object.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
wood burning stoves
 
subject: equals()