Avoiding != null statements The idiom I use the most when programming in Java is to test if object != null before I use it. This is to avoid a NullPointerException. I find the code very ugly, and it becomes unreadable. Is there a good alternative to this? I want to address the necessity to test every object if you want to access a field or method of this object. For example: if (someobject != null) { someobject.doCalc(); } In this case I will avoid a NullPointerException,