I have been asked to prefer using Optional class to avoid null pointer exception but I am not sure how will it help dramatically, as anyway we still have to apply a check optional.isPresent()
to avoid getting exception just like null check.
I don't see that it's very useful unless we use optional.or()
to override with some default value or most of the time with an empty object.
Is there any other benefit, which I am missing to see, otherwise this can be easily avoided without getting any extra overhead?