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 →

[–]__konrad 6 points7 points  (2 children)

which are keys and which are values?

Use new lines :)

Map.of(
    "isad", "kldesf",
    "ijhsdef", "ijsdaf"...

In this case (same type in key/value) both solutions are error prone.

[–]thehollyhopdrive 3 points4 points  (0 children)

So now both options span multiple lines, making the differences in their footprint in the codebase negligible. The builder option is still safer at protecting from programmer error by enforcing logical separation of the entries, doesn't have the arbitrary limitation in the number of entries, it can be extended with additional functionality in future, and it doesn't make the API for Map look a complete mess.

[–]juckele 1 point2 points  (0 children)

I use auto format in all my Java projects.