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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top