Re:Deprecating: java.util.Optional.get()?
by lmm on Thursday April 28, 2016 @11:28AM
(#11589561)
Defensive programming in the form of checking all parameters and all return values from library methods for null? Sure, good idea. But then you need a way to distinguish between things that should never be null and things that genuinely might not be present. So Optional is one of the pieces you need to enable this kind of style.
[ Parent
| on HN ]
Re:Deprecating: java.util.Optional.get()?
by specialist on Thursday April 28, 2016 @12:20PM
(#11589948)
"distinguish between things that should never be null and ... might not be present"
My strategy is to use Enums. And no autoboxing. And use NullObjects.
Enums don't have (dynamic) data members, do they? Sometimes you want a representation of e.g. "user's email address, or nothing if they haven't set one". More, you want that often enough that it's worth having a single generic way to represent it rather than having to construct a custom NullObject for each case.