str.equals(null) or str==null ?

A

AndrewMcDonagh

Bhanu said:
"null" is not an object of any class null implies that it does not
refers to any object. So u can not do obj.eqals(null) for any object.
U need to pass as an object as the argument.

in this case you can, as the String.equals() method will return false if
passed a null.
 
O

Oliver Wong

Bhanu said:
"null" is not an object of any class null implies that it does not
refers to any object. So u can not do obj.eqals(null) for any object.
U need to pass as an object as the argument.

If you actually try it in your compiler, you'll see that
obj.equals(null) compiles just fine, and produces the expected result of
returning false (assuming obj is also not null).

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,625
Members
45,321
Latest member
AlphonsoPi

Latest Threads

Top