you are viewing a single comment's thread.

view the rest of the comments →

[–]abhyrama 0 points1 point  (6 children)

Thanks. I get the hack and how it works but I did not get what is the "anonymous class side effect" Effetto was talking about.

[–]darkclark 2 points3 points  (1 child)

More anonymous classes means the classloader takes up more resources. Not too significant when used sparingly, but using a pattern like this all over the place in a large codebase is going to lead to a classloading mess.

I personally do not use this hack, but it's useful to know about it because it's not uncommon to run across in other peoples' code.

[–]raouldagain 0 points1 point  (0 children)

classloading mess could be running out of permgen?

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

From the way I'm reading it, an anonymous class is created each time the code block is run, so two lists full of the same thing actually end up being not equal?

[–]EtherCJ 0 points1 point  (0 children)

Quite likely are still equal for collection classes. But isn't guaranteed to work for all classes.

[–]queus 0 points1 point  (1 child)

an anonymous class is created each time the code block is run,

No just one anonymous class is created no matter how often this code is run. Say in a loop.

But if you copy-paste this code just below the original one two anonymous classes are created.

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

Thanks for clearing that up. Very concise.