2
kshep92
8y

I HATE dealing with Map objects in Java. Much like everything else in Java, the API is far too verbose. What's more annoying is how Oracle seems unbothered to improve it.

Comments
  • 1
    Map API is verbose?
  • 1
    When compared to Groovy:

    def foo = [bar: 1, baz: "something"]

    Java:

    Map<String, Object> foo = new HashMap<>();

    foo.put("bar", 1);
    foo.put("baz", "something");

    Imagine doing that for a more complex dictionary. They implemented lambda expressions but won't implement a shortcut API for Maps.
  • 0
    I agree. Guava's ImmutableMap.of is what I tend to use for simpler entries
  • 1
    @kshep92 what you're showing is a problem in a script... Not in an enterprise software, and that's what Java is good at.
    I far prefer working with the Java verbosity on a real project than Python's (for example) magic
  • 0
    @willol script or enterprise app (the latter of which I do write a lot of) I don't want to aggravate my carpal tunnel to communicate a simple idea to the compiler. I find by now there should be an easier way of defining dictionaries in Java.
Add Comment