JDK7 Tackles Java Verbosity

Interesting article showing some changes on the Java platform to address its verbosity, but keeping code readability safe.
I liked the new Collection’s literals syntax to create lists, sets and maps:

List powersOf2 = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
Map ages = {"John" : 35, "Mary" : 28, "Steve" : 42};

Although it can be possible to use the DoubleBraceInitialization idiom to initialize collections in a more elegant way, this syntax is very terse and concise.

BTW, as I said before, Scala already has a syntactic sugar to create a literal Map:

val ages = Map("John" -> 35, "Mary" -> 28, "Steve" -> 42)

Maybe this change was taken into account considering the Scala collection literals implementation?

2 Replies to “JDK7 Tackles Java Verbosity”

  1. I’m still more fond of the Groovy syntax to Lists and Maps:

    def list = [5, 6, 7, 8]

    def map = [name:”Gromit”, likes:”cheese”, id:1234]


Leave a Reply to Mathieu Cancel reply

Your email address will not be published. Required fields are marked *