What is Double Brace initialization in Java? -
what double brace initialization syntax ({{ ... }}
) in java?
double brace initialisation creates anonymous class derived specified class (the outer braces), , provides initialiser block within class (the inner braces). e.g.
new arraylist<integer>() {{ add(1); add(2); }};
note effect of using double brace initialisation you're creating anonymous inner classes. created class has implicit this
pointer surrounding outer class. whilst not problem, can cause grief in circumstances e.g. when serialising or garbage collecting, , it's worth being aware of this.
Comments
Post a Comment