Live data from Hacker News

Double Brace Initialization in Java

c2.com

1–10 of 28 posts

Re: Double Brace Initialization in Java

#3
I had known of this before, and I'm fairly certain I've used it before. However, one thing I didn't consider is the equals issue commented on the site. As attractive as it may be to use, I think from now on I will refrain from using the double braces.

Re: Double Brace Initialization in Java

#5

I had known of this before, and I'm fairly certain I've used it before. However, one thing I didn't consider is the equals issue commented on the site. As attractive as it may be to use, I think from now on I will refrain from using the double braces.

> I had known of this before, and I'm fairly certain I've used it before.

I consider myself pretty liberal when it comes to coding standards and being clever, but this is something that will badly piss me off. I can't quite put my finger on why I feel so, considering I am perfectly fine with most of the perl tricks. For example, https://gist.github.com/3392206 looks good to me(you are using Perl, you should know about list and scalar contexts).

Re: Double Brace Initialization in Java

#6
post #4

This just makes me glad I don't have to write Java any more.

> 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

#7
post #2

Check out the Immutable Maps feature, does the same with some nice syntactic sugar - http://docs.guava-libraries.googlecode.com/git/javadoc/com/g...

You don't even need to use the Builder directly, just use the structure's "of" method:

   ImmutableSet foos = ImmutableSet.of(a, few, elements);
   ImmutableMap map = ImmutableMap.of(k1, v1, k2, v2);

Re: Double Brace Initialization in Java

#8
post #5

I had known of this before, and I'm fairly certain I've used it before. However, one thing I didn't consider is the equals issue commented on the site. As attractive as it may be to use, I think from now on I will refrain from using the double braces.

> I had known of this before, and I'm fairly certain I've used it before. I consider myself pretty liberal when it comes to coding standards and being clever, but this is something that will badly piss me off. I can't quite put my finger on why I feel so, considering I am perfectly fine with most of the perl tricks. For example, https://gist.github.com/3392206 looks good to me(you are using Perl, you should know abou…

Ah yes, the goatse operator.

Re: Double Brace Initialization in Java

#9
post #6
post #4

This just makes me glad I don't have to write Java any more.

> 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.

The issue of course is that both the clever way and the 'normal' way are not exactly pleasant compared to most other modern languages.
Post reply on HN