Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.522 :

Posted: Wed Oct 08, 2014 8:36 am
by piotrkmiotczyk
If passed a null it can also throw a NullPointerException, right? E.g.:

TestClass tc2 = null;
System.out.println(tc2.equals(null)); //does not return false, but throws NPE

(I picked answer "none of the above" instead of answer "must return false" because of this).

Re: About Question com.enthuware.ets.scjp.v6.2.522 :

Posted: Wed Oct 08, 2014 12:12 pm
by admin
No, as per the requirements of the equals method, you pass a null, it should return false and not throw NPE. If a class throws NPE, then it is not an appropriate implementation of equals method.

HTH,
Paul.