<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean Cook &#187; Java</title>
	<atom:link href="http://www.seancook.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.seancook.com</link>
	<description>ramblings on mobile software, devices, and life</description>
	<lastBuildDate>Mon, 17 Aug 2009 15:40:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Double Brace Initialization in Java</title>
		<link>http://www.seancook.com/2008/07/18/double-brace-initialization-in-java/</link>
		<comments>http://www.seancook.com/2008/07/18/double-brace-initialization-in-java/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 18:10:57 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.seancook.local/?p=3</guid>
		<description><![CDATA[When I was working on my thesis for graduate school I spent months reading all that I could on optimizations that Java coders could consciously utilize while coding. While that was as exciting as it sounds*, I did manage to stumble across a few Java idioms that I’m surprised I don’t see used more often. [...]]]></description>
			<content:encoded><![CDATA[<p>When I was working on my thesis for graduate school I spent months reading all that I could on optimizations that Java coders could consciously utilize while coding. While that was as exciting as it sounds*, I did manage to stumble across a few Java idioms that I’m surprised I don’t see used more often. One of my favorite idioms that I still use from time to time is called <a href="http://c2.com/cgi/wiki?DoubleBraceInitialization">Double Brace Initialization</a>.  It’s a simple way to initialize collections, and I personally feel that it makes code more readable.</p>
<p>Instead of this:</p>
<pre name="code" class="java">
private Map<Object,Integer> map = new HashMap<Object,Integer>();
map.put(obj1, 3);
map.put(obj2, 4);
/*  yada yada yada */
</pre>
<p>You can do this:</p>
<pre name="code" class="java">
private Map<Object,Integer> map = new HashMap<Object,Integer>(){{
put(obj1, 3);
put(obj2, 4);
/* yada yada yada */
}}
</pre>
<p>The first brace creates an anonymous inner class, and the second brace creates an initializer block that is executed when the anonymous class is created.</p>
<p>__</p>
<p>*it really wasn’t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seancook.com/2008/07/18/double-brace-initialization-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
