Re:Double Brace Initialization in Java
by guard-of-terra on Sunday August 19, 2012 @08:25AM
(#4403836)
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.
In the majority of cases where you are deploying your java code on a server you own, having a few dozen or hundred extra classes is not a big deal. Each adds maybe a few kb to the size the jar, and as for loading costs, a class is only loaded into a running JVM once.
The cases in which to worry about stuff like this is if you need to load the code on someone else's machine, like with an applet or Android.
Re:Double Brace Initialization in Java
by jimktrains2 on Sunday August 19, 2012 @12:10PM
(#4404370)
Isn't this what jars are suppose to make transparent and simple?
Re:Double Brace Initialization in Java
by mindslight on Sunday August 19, 2012 @11:09AM
(#4404192)
It's one class per use of this technique. It's not redefined every time the code runs.
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...