aspose file tools*
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 Java 8 in Action this week in the Java 8 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: equals()
 
Similar Threads
Autoboxing vs Unboxing
Related to Boxing
logical operator doubt
Boolean == Vs .equals()
Boolean construction(new/valueOf) - why different result?