Monday, May 20, 2019

Replacing null checks

This article introduces some patterns for replacing the "old" null-check pattern.

I.e. instead of:
if (value != null) { doSomething(value); } 
do:
Optional maybeValue = Optional.ofNullable(value); if (maybeValue.isPresent()) { doSomething(maybeValue.get()); }

No comments:

Post a Comment