News for hackers. Stuff that matters.
Re:Double Brace Initialization in Java by jfb on Sunday August 19, 2012 @01:04AM (#4403260)
This just makes me glad I don't have to write Java any more.
Re:Double Brace Initialization in Java by irahul on Sunday August 19, 2012 @01:10AM (#4403268)
> This just makes me glad I don't have to write Java any more.

You don't have to do it even if you are writing Java. This is a perfect example of clever for the sake of being clever.

Re:Double Brace Initialization in Java by jlgreco on Sunday August 19, 2012 @01:52AM (#4403350)
The issue of course is that both the clever way and the 'normal' way are not exactly pleasant compared to most other modern languages.
Re:Double Brace Initialization in Java by J446 on Sunday August 19, 2012 @11:17AM (#4404213)
That depends if you mean Java the language or Java the platform. Java the language is to include immutable collection literals in JDK8:

http://jcp.org/en/jsr/detail?id=337

Today Java lets you do the following:

List<String> myList = Arrays.asList("one", "two", "three");

Scala and Groovy which target the JVM let you do things like:

Scala: val myList = List("one", "two", "three")

Groovy: def myList = ["one", "two", "three"]

Then there's JRuby, Jython etc.

Re:Double Brace Initialization in Java by Macha on Sunday August 19, 2012 @11:28AM (#4404247)
> List<String> myList = Arrays.asList("one", "two", "three");

This is often not good enough, as Arrays.asList returns some internal immutable List type. If you then tried to do something like myList.add("four"); you'd get an exception.

What you'd actually need to do is something more like:

> List<String> myList = new ArrayList<String>(Arrays.asList("one", "two", "three"));

Compare that to more dynamic languages, where that example would be:

> myList = ["one", "two", "three"]

Yes, it's a trivial example, but it's something many programs involve all over the place, and the boilerplate adds up a tedious task.