jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equals method 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 method" Watch "equals method" New topic

equals method

Smitha Ballikar
Ranch Hand

Joined: Aug 02, 2005
Posts: 99

Here it gives compiler error.I thought it would print "We are not Equal".
Cant we use null with equals method??
Rushikesh Wagh
Ranch Hand

Joined: Jun 18, 2005
Posts: 58
.equals() Method Is Used To Compare The Objects And null Is Not An Object. Hence It Has Compile Time Error. Please Do Correct Me If I m Wrong.

Best Regards,
Rushikesh Wagh
SCJP 1.4 (2005)
SCJP 1.6 (2010)
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
Rushikesh is correct, null is a literal, not an object. Trying to call a method on null would be like trying to call a method on the number 5 or the boolean value true.
raghu babu
Ranch Hand

Joined: Jul 05, 2005
Posts: 60
on the same lines, try this :

Byte b2 = new Byte("11");

if(b2.toString() == b2.toString())
subject: equals method
It's not a secret anymore!