I have gone through several null check related questions in Java and the best practices around it.
After long search , I can see Objects.nonNull ()
serves the purpose though it looks Orange instead of Apple.
Now i have a following check using Objects.nonNull()
and short-circuiting logical AND.
if (Objects.nonNull (obj1) &&
Objects.nonNull (obj1.getObj2()) &&
Objects.nonNull (obj1.getObj2().getObj3 ())
{
obj1.getObj2().getObj3().doSomething();
}
I find it is more redundant and less readable when i clearly know my intention.
Is there any other approach to handle it in functional way to assert the non null state of the deeper object without facing Null pointer exception.