This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
// here your are invoking some methods on other objects
Should we check for non nullness of otherObject as well , if its null it will throw NPE.
What does the best practice says about validatin an object before invoking any methods on them .
Joined: Oct 13, 2005
You should have checked otherObject is not null earlier. If it is a field, it ought to be initialised in the constructor. If it is set by a set method, that set method ought to check for nullity and throw a NullPointerException if null is passed. As John Bengler says, "crash early".
Joined: Sep 07, 2009
David Newton wrote:Is the argument *likely* to be null? Or is it a programming error if it's null?