<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Instantiating and populating a list or collection</title>
	<atom:link href="http://gabrito.com/post/instantiating-and-populating-a-list-or-collection/feed" rel="self" type="application/rss+xml" />
	<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection</link>
	<description>Anecdotes on Java, Ruby, Sysadmin, SEO, Design, and Management</description>
	<pubDate>Thu, 04 Dec 2008 17:52:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Ricky Clarkson</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10582</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Tue, 21 Nov 2006 16:10:03 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10582</guid>
		<description>Yes, using a static import it's fine.  I half-meant Arrays.asList, but which asList you use isn't so important to the meaning of my post.  Arrays.asList returns a read-only list, so you might prefer to write your own asList implementation.

It's odd that after three years or so of static imports people still look at them oddly.  Blog posters don't expect me to qualify the package part, but they do expect the class part. ;)

Sorry for the diversion, but I think static methods really belong outside classes; they're not OO, so they shouldn't look like they are.  Not that being non-OO is a problem, mind..

import static java.util.asList; //would suit me.</description>
		<content:encoded><![CDATA[<p>Yes, using a static import it&#8217;s fine.  I half-meant Arrays.asList, but which asList you use isn&#8217;t so important to the meaning of my post.  Arrays.asList returns a read-only list, so you might prefer to write your own asList implementation.</p>
<p>It&#8217;s odd that after three years or so of static imports people still look at them oddly.  Blog posters don&#8217;t expect me to qualify the package part, but they do expect the class part. <img src='http://gabrito.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Sorry for the diversion, but I think static methods really belong outside classes; they&#8217;re not OO, so they shouldn&#8217;t look like they are.  Not that being non-OO is a problem, mind..</p>
<p>import static java.util.asList; //would suit me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afsina</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10576</link>
		<dc:creator>afsina</dc:creator>
		<pubDate>Tue, 21 Nov 2006 14:53:33 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10576</guid>
		<description>Ricky, you got me there.. i totally forget that. should be  Arrays.asList(...) tough. maybe using static import, the way you write is fine..</description>
		<content:encoded><![CDATA[<p>Ricky, you got me there.. i totally forget that. should be  Arrays.asList(&#8230;) tough. maybe using static import, the way you write is fine..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10573</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Tue, 21 Nov 2006 14:14:08 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10573</guid>
		<description>[] for generics, as there's no preview button:

I wonder what's wrong with List[String] list=asList("rocks","my","world");</description>
		<content:encoded><![CDATA[<p>[] for generics, as there&#8217;s no preview button:</p>
<p>I wonder what&#8217;s wrong with List[String] list=asList(&#8221;rocks&#8221;,&#8221;my&#8221;,&#8221;world&#8221;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afsina</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10571</link>
		<dc:creator>afsina</dc:creator>
		<pubDate>Tue, 21 Nov 2006 13:53:35 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10571</guid>
		<description>actually, i saw that i did wirte "real code" my intention was to say "real business logic" pardon my english :P</description>
		<content:encoded><![CDATA[<p>actually, i saw that i did wirte &#8220;real code&#8221; my intention was to say &#8220;real business logic&#8221; pardon my english <img src='http://gabrito.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afsina</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10570</link>
		<dc:creator>afsina</dc:creator>
		<pubDate>Tue, 21 Nov 2006 13:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10570</guid>
		<description>Todd:
i did not say tests are not real code, however, it is easy to introduce those methods in a test base class, which is cleaner then the solutions you offered. 

http://jroller.com/page/ff?entry=initializing_collections_my_take

i dont think there is a shortcoming of Java on this. This is the Java way, if writing a two line method will give you more or less the same result, it is better then introducing a new syntax to the language.</description>
		<content:encoded><![CDATA[<p>Todd:<br />
i did not say tests are not real code, however, it is easy to introduce those methods in a test base class, which is cleaner then the solutions you offered. </p>
<p><a href="http://jroller.com/page/ff?entry=initializing_collections_my_take" rel="nofollow">http://jroller.com/page/ff?entry=initializing_collections_my_take</a></p>
<p>i dont think there is a shortcoming of Java on this. This is the Java way, if writing a two line method will give you more or less the same result, it is better then introducing a new syntax to the language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Schneller's Weblog</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10553</link>
		<dc:creator>Daniel Schneller's Weblog</dc:creator>
		<pubDate>Tue, 21 Nov 2006 11:33:11 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10553</guid>
		<description>&lt;strong&gt;Amazingly simple - Collection Initialization...&lt;/strong&gt;

On  Todd Huss ' blog I just came about a very simple way of initializing a collection with a set of predefined values. It is so simple that it is amazing people do not use it way more often. For my part, I have seen this use of instance initializers f...</description>
		<content:encoded><![CDATA[<p><strong>Amazingly simple - Collection Initialization&#8230;</strong></p>
<p>On  Todd Huss &#8216; blog I just came about a very simple way of initializing a collection with a set of predefined values. It is so simple that it is amazing people do not use it way more often. For my part, I have seen this use of instance initializers f&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd Huss</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10499</link>
		<dc:creator>Todd Huss</dc:creator>
		<pubDate>Tue, 21 Nov 2006 05:22:17 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10499</guid>
		<description>afsina, I disagree that those types of initializations are not needed in real code, tests are real code. If you're creating a helper method just to create a simple data structure like an array more elegantly, then I'd say the language is coming up short on that front whether it's in a test or production code and let's face it, it's just lame that Java won't let us construct a collection with its contents!</description>
		<content:encoded><![CDATA[<p>afsina, I disagree that those types of initializations are not needed in real code, tests are real code. If you&#8217;re creating a helper method just to create a simple data structure like an array more elegantly, then I&#8217;d say the language is coming up short on that front whether it&#8217;s in a test or production code and let&#8217;s face it, it&#8217;s just lame that Java won&#8217;t let us construct a collection with its contents!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afsina</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10493</link>
		<dc:creator>afsina</dc:creator>
		<pubDate>Tue, 21 Nov 2006 04:19:01 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10493</guid>
		<description>oh by the way, blog ate my  (greater, smaller)  symbols..</description>
		<content:encoded><![CDATA[<p>oh by the way, blog ate my  (greater, smaller)  symbols..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afsina</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10492</link>
		<dc:creator>afsina</dc:creator>
		<pubDate>Tue, 21 Nov 2006 04:14:58 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10492</guid>
		<description>sorry it was suppose ot be :

List l = makeAList(State.CA, State.NY, State.WY)</description>
		<content:encoded><![CDATA[<p>sorry it was suppose ot be :</p>
<p>List l = makeAList(State.CA, State.NY, State.WY)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: afsina</title>
		<link>http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10490</link>
		<dc:creator>afsina</dc:creator>
		<pubDate>Tue, 21 Nov 2006 04:13:45 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/instantiating-and-populating-a-list-or-collection#comment-10490</guid>
		<description>Java is about code reuse and modularity. Usually this kind of initializations are not needed in real code. it is rather used in tests. so best way is to prepare some simple helpers (maybe in test base class or as a static method) using varargs such as :

    public  List makeAList(T... elements) {
        return Arrays.asList(elements);
    }


    public  Set makeHSet(T... elements) {
        return new HashSet(makeAList(elements));
    }


then call: 

List l = makeList(State.CA, State.NY, State.WY)

i dont know but it seems pretty neat and clear to me.</description>
		<content:encoded><![CDATA[<p>Java is about code reuse and modularity. Usually this kind of initializations are not needed in real code. it is rather used in tests. so best way is to prepare some simple helpers (maybe in test base class or as a static method) using varargs such as :</p>
<p>    public  List makeAList(T&#8230; elements) {<br />
        return Arrays.asList(elements);<br />
    }</p>
<p>    public  Set makeHSet(T&#8230; elements) {<br />
        return new HashSet(makeAList(elements));<br />
    }</p>
<p>then call: </p>
<p>List l = makeList(State.CA, State.NY, State.WY)</p>
<p>i dont know but it seems pretty neat and clear to me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
