Joined February 2012
·

Ryan Ransford

Genscape
·
Louisville, KY
·
·
·

Posted to Easier Java object initialization over 1 year ago

This is also a useful technique when initializing Map and List instances. But, having seen many people concerned about performance, I typically reserve its usage to my tests.

Example:
final List<String> list = new ArrayList<String>() {{
add("value1");
add("value2");
}}
final Map<String, String> map = new HashMap<String, String>() {{
put("key1", "value1");
put("key2", "value2");
}}

Achievements
59 Karma
0 Total ProTip Views