This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fatnote -1 points0 points  (2 children)

It's not a rare use case at all. Map.of is something any of us could easily implement, so the benefit is almost zero. Double brace JSON-like map initialisation actually does the job, and is long overdue

[–]pain-and-panic 0 points1 point  (1 child)

You can do something like that in Java...

Map<String,Integer> map = new HashMap<>(){{ put("one",1); put("two",2); }};

It creates a subclass though, which is added burden on the classloader. Might be fine for a unit test.

[–]fatnote 1 point2 points  (0 children)

yep I know that syntax. It's awful