This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: equals()
 
It's not a secret anymore!