星期五, 七月 05, 2013

Java Double Brace Initialization

常用语Java Collect类的初始化,因为Java没有提供简易的初始化Collect的方法。
Set<String> flavors = new HashSet<String>() {{      add("vanilla");      add("strawberry");      add("chocolate");      add("butter pecan");  }};

The first brace creates a new AnonymousInnerClass,
the second declares an instance initializer block that is run when the anonymous inner class is instantiated.

 add(new JPanel() {{  	setLayout(...);  	setBorder(...);  	add(new JLabel(...));  	add(new JSpinner(...));   }});