Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

how to Avoiding “!= null” statements in Java?

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?

Update: Pan, I was not clear with my question. 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) {

In this case I will avoid a NullPointerException, and I don't know exactly if the object is null or not. So my code get splattered with these tests.

asked May 15, 2015 in Core java by rajesh
0 votes

Related Hot Questions

Government Jobs Opening