Open minds leads to freedom

Communicating my thoughts on software development

JDK7 Tackles Java Verbosity

Posted by rnaufal on September 22nd, 2009

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?

Share and Enjoy:
  • Twitter
  • Digg
  • del.icio.us
  • Reddit
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Technorati
  • FriendFeed
  • Google Buzz
  • MySpace
  • Slashdot
  • http://rails.anyware-technologies.com.br Mathieu

    Ruby:

    myhash = {“A”=>100, “b”=>100}

    ;-)

  • http://bpfurtado.livejournal.com/ Bruno

    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]

    :)