How to avoid object != null condition check in Java?

0 votes
436 views
asked Jan 18 by Hitesh Garg (352 points)  

We were having a lot of NullPointerExceptions in our system due to which we end up having a lot of object != null conditions in our code.

Although some places we are sure that the Null pointer will never be thrown from a certain section of code but when someone else is implementing the code then we are not sure whether it will throw Null pointer or not and then we end up having the same condition again, which is completely useless.

Is there any other alternative for that?

For example:

if (someobject != null) {
    someobject.doCalc();
}

Please log in or register to answer this question.

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...