in several projects I saw developers tendency to subclass anonymously say HashSet
to mimic Set literal of some sort.
Set<String> set = new HashSet<String>() {{
add("a");
add("b");
}};
So what happens here is we're creating anonymous class and abusing it's instance initializer to add some items to Set. Personally, I consider it as a bad style, because of initializer, which we normally trying to avoid and because of pointless generation of another .class file. Sure, eyes hurts from that, but is it actually that bad? I mean nowadays we're getting one class file for every lambda anyways, so ...
What do you think?