Skip to content

Comment on Deprecating: java.util.Optional.get()?parent

Comments

Really?

  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;
    }
    ...
  }

Urgh. Sure that's one option, but I don't want to have to subclass HashMap every time I want to store something different in it. Also sometimes I want generic code that uses a map.

And sometimes you want a different type of map...

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.