Hacker News new | ask | show | jobs
by jmmcd 5479 days ago

    Map m = new HashMap();
    m.put("a", 1);
    m.put("b", 2);
    m.put("c", 3);
    .
    .
    .
The single worst thing in Java?
1 comments

I think the current way to write that is to either use Google Guave ImmutableMap.of("a", 1, "b", 2, "c", 3) or when mutable maps are required, to write: Map m = new HashMap() {{ put("a", 1); put("b", 2); put("c", 3); }};

Both of these are a bit lighter yet still far away from JavaScript or Ruby special syntaxes.