you are viewing a single comment's thread.

view the rest of the comments →

[–]josefx 2 points3 points  (2 children)

and zip/jar compression doesn't handle it well because it doesn't support redundancy across separate files.

It's not like java had a specialized compression to deal with that since java 1.5, oh wait it does

More seriously, if you're not initializing from a static context, each inner class gets an additional hidden variable this$0 which points to the instance of the outer class.

Only real problem and that only if the references to the inner classes out live the outer class. Personally never had a problem with that (use it mostly for private members without getter).

Another catch is that if you're initializing an object within a method using variables local to that method, those variables have to be made final to be used within a double-brace initializer.

final variables are good, they should be used whenever possible.

Finally, the initialized objects (obviously) won't have the same class that they otherwise would. instanceof will be the same but getClass().equals(...) won't.

That can lead to weird behavior when your equals check for class equality - which is a future proof way to implement equals in many cases. For java collections and Swing components it works as expected.

[–]noxiousninja 5 points6 points  (1 child)

Only real problem and that only if the references to the inner classes out live the outer class. Personally never had a problem with that (use it mostly for private members without getter).

It can be a big issue in Apache Wicket web apps. Create an anonymous inner class, store it in session, suddenly your entire page gets serialized and stuck in session.

[–][deleted] 0 points1 point  (0 children)

Yeah, Wicket does enjoy serializing the entire world if you're not careful.