Avoiding NullPointerException in Java
Asked 07 September, 2021
Viewed 2.6K times
  • 50
Votes

I use object != null a lot to avoid NullPointerException.

What is an alternative to:

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

30 Answer