One thing though. I love this technique but the home built Eclipse compiler is not fully Java language compliant and it will reject certain forms of this as invalid. Specifically, the sun and eclipse compiler treat "this" differently in these code blocks. My project will not compile under eclipse because of certain usages of this pattern when combined with inner classes. The bug crops up when you need to pass the parent to the child object being initialized in the static block.
Java Hack: Double Brace Initialization
21–22 of 22 posts
Re: Java Hack: Double Brace Initialization
#22This is where Google Collections comes in handy:
Lists.newArrayList(1, 2, 3)
Or, if you don't need to modify it: ImmutableList.of(1, 2, 3)
Such an awesome library.