3 ms·
Java's Optional is exactly unlike a NullObject. Optional is not a Proxy. Being untyped, not being an implementation of the interface, it can't be used interchan
by specialist 11y ago
Java's Optional is exactly unlike a NullObject. Optional is not a Proxy. Being untyped, not being an implementation of the interface, it can't be used interchangeably.
It's NullObjects all the way down. Makes more sense when designs favor compositions over inheritance.
Optional is the wrapper no one needed. For syntactic sugar, static library methods worked just fine.
- lmm 11y agoSo once again, if you didn't have Optional, what should Map#get return?
- specialist 11y agoReally? class Widget {...} class final NullWidget extends Widget { static NULL_WIDGET = new NullWidget(); ... } class WidgetMap extends HashMap<String,Widget> { Widget get( String key ) { if( contains( key )) { return super.get( key ); } return NULL_WIDGET; } ... }
- dangerlibrary 11y agoAm I missing something? Optional<String> can't contain an integer - it's either empty or contains a String. It certainly looks typed from where I sit.