Live data from Hacker News

Double Brace Initialization in Java

c2.com

11–20 of 28 posts

Re: Double Brace Initialization in Java

#13
I know this is blasphemy in the Java world, but I'd probably use a preprocessor to transform some clean syntax into the normal Java code. I'd rather have the slight increase in build complexity over the potential issues with the extra classes and the breaking of assumption about how things compare and such.

Re: Double Brace Initialization in Java

#14
post #13

I know this is blasphemy in the Java world, but I'd probably use a preprocessor to transform some clean syntax into the normal Java code. I'd rather have the slight increase in build complexity over the potential issues with the extra classes and the breaking of assumption about how things compare and such.

I have always been extremely tempted to just throw together a quick and dirty preprocessor in maybe Awk for the few personal projects that I've used Java for. It would just make everything so much nicer.

Re: Double Brace Initialization in Java

#15
post #14
post #13

I know this is blasphemy in the Java world, but I'd probably use a preprocessor to transform some clean syntax into the normal Java code. I'd rather have the slight increase in build complexity over the potential issues with the extra classes and the breaking of assumption about how things compare and such.

I have always been extremely tempted to just throw together a quick and dirty preprocessor in maybe Awk for the few personal projects that I've used Java for. It would just make everything so much nicer .

[deleted]

Re: Double Brace Initialization in Java

#16
I am no Java expert but they write that this syntax automatically creates a anonymous inner class - every time you create a collection instance in this way. Or am I wrong about this?

Most of the examples given are creating static objects but the last example a non-static object is created in the same way. Imagine you are doing this a couple of times then you end up with a lot of anonymous classes. Isn't there a limit on the number of classes you can have? At least it makes debugging problematic.

But I might be wrong about this since I am not a Java expert...

Re: Double Brace Initialization in Java

#17
post #13

I know this is blasphemy in the Java world, but I'd probably use a preprocessor to transform some clean syntax into the normal Java code. I'd rather have the slight increase in build complexity over the potential issues with the extra classes and the breaking of assumption about how things compare and such.

Something like Xtend ( http://www.eclipse.org/xtend/ ) ?

Re: Double Brace Initialization in Java

#18

I am no Java expert but they write that this syntax automatically creates a anonymous inner class - every time you create a collection instance in this way. Or am I wrong about this? Most of the examples given are creating static objects but the last example a non-static object is created in the same way. Imagine you are doing this a couple of times then you end up with a lot of anonymous classes. Isn't there a limit…

In Java, you have a gazzilion of classes. You have seriolusly many classes. And if you use Clojure or Scala or JRuby, you number of classes multiplies.

You just stuff a hundred of jars full of classes into your classpath and never look back.

JVM hums happily and does not care about however much classes you have. No problems with debugging either because why would it be? Anonymous classes are as introspective as non-anonymous.

Re: Double Brace Initialization in Java

#19
post #13

I know this is blasphemy in the Java world, but I'd probably use a preprocessor to transform some clean syntax into the normal Java code. I'd rather have the slight increase in build complexity over the potential issues with the extra classes and the breaking of assumption about how things compare and such.

Your IDE would complain all the time. Seriously, you lose one of a few good parts, stellar IDE support. Why bother with Java then?

Re: Double Brace Initialization in Java

#20
post #13

I know this is blasphemy in the Java world, but I'd probably use a preprocessor to transform some clean syntax into the normal Java code. I'd rather have the slight increase in build complexity over the potential issues with the extra classes and the breaking of assumption about how things compare and such.

> I'd probably use a preprocessor to transform some clean syntax into the normal Java code.

If I were in your place, I'd just learn enough Java to be proficient. Java is a very powerful language and certainly better suited for mundane tasks than your preprocessor.

Post reply on HN