Before calling a function of an object, I need to check if the object is null, to avoid throwing a NullPointerException.
NullPointerException
What is the best way to go abou
We can use Object.requireNonNull static method of Object class. Implementation is below
public void someMethod(SomeClass obj) { Objects.requireNonNull(obj, "Validation error, obj cannot be null"); }