<?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"
	>

<channel>
	<title>!</title>
	<atom:link href="http://info.dabarobjects.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://info.dabarobjects.com</link>
	<description>Information, Views and News</description>
	<pubDate>Wed, 04 Jun 2008 21:42:31 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Some Little Generics Suggestion</title>
		<link>http://info.dabarobjects.com/2008/06/03/some-little-generics-suggestion/</link>
		<comments>http://info.dabarobjects.com/2008/06/03/some-little-generics-suggestion/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 23:47:45 +0000</pubDate>
		<dc:creator>dabar</dc:creator>
		
		<category><![CDATA[java]]></category>

		<category><![CDATA[technology]]></category>

		<category><![CDATA[java generics suggestion]]></category>

		<guid isPermaLink="false">http://info.dabarobjects.com/?p=5</guid>
		<description><![CDATA[There has been a lot of issues about Generics generally. Personally my dislike for Generics was rekindled again when my favourite web framework (Wicket) almost had issues taking us the generics way.
Please, I am no JVM engineer but with my little knowledge of Java, I kind of use my imagination to think about ways of [...]]]></description>
			<content:encoded><![CDATA[<p>There has been a lot of issues about Generics generally. Personally my dislike for Generics was rekindled again when my favourite web framework (Wicket) almost had issues taking us the generics way.</p>
<p>Please, I am no JVM engineer but with my little knowledge of Java, I kind of use my imagination to think about ways of making things simpler.</p>
<p>Now, For instance take a look at this simple errornoues implementation of a newbie Generics user:</p>
<p><code>public class SomeGenericType&lt;T&gt; {<br />
public Class&lt;T&gt; getGenericsTypeClass(){<br />
return T.class; //off course this is not possible. I have taken this step once. Thank God for modern IDEs<br />
}<br />
}</code></p>
<p>Now after learning the right thing, the code above will now become something like this:</p>
<p><code>public class SomeGenericsType&lt;T&gt; {<br />
private Class&lt;T&gt; genericTypeClass;<br />
public SomeGenericsType(Class&lt;T&gt; clazz){<br />
this.genericTypeClass = clazz;<br />
}<br />
public Class&lt;T&gt; getGenericsTypeClass(){<br />
return genericTypeClass; //now this will compile<br />
}<br />
}</code></p>
<p>because of this implementation, we are suffering from too much repitition like this</p>
<p><code>SomeGenericsType&lt;MyType&gt; someGenericType = new SomeGenericType&lt;MyType&gt;(MyType.class);</code></p>
<p>and can be harsh on API designers and users.<br />
look at this</p>
<p><code>SomeOtherTypes&lt;MyKey,MyType&gt; someOtherTypes = new SomeOtherTypes&lt;MyKey,MyType&gt;(MyKey.class, MyType.class); //I think this is not fun</code></p>
<p>However, JDK5.0 introduced a particular feature called Annotation and from my little knowledge, I know that certain annotations like <strong>@SuppressWarning</strong> gives messages to the compiler.</p>
<p>Now this is what my little imagination is messing with.</p>
<p>Why will it be impossible or why is it not technically sound or feasible or unreasonable to have this little enhancement to Java giving us a little assistance from the compiler with Generics.</p>
<p><code>public class SomeGenericsType&lt;T&gt;{<br />
<strong> @InjectType</strong> //a compiler annotation<br />
<strong> private Class&lt;T&gt; genericsTypeClass;</strong><br />
public SomeGenericsType(){<br />
//no need to pass Class as constructor argument again<br />
}<br />
public Class&lt;T&gt; getGenericsTypeClass(){<br />
return genericTypeClass;<br />
}<br />
}</code><br />
Now during compilation, the compiler will read the annotation <strong>@InjectType</strong> and will inject the Parameter Types. It will simply help us reengineer the code so that <strong>Class&lt;T&gt; genericsTypeClass</strong> changes to <strong>Class genericTypeClass = MyType.class;</strong></p>
<p>I think like this, we can have a little hint of our generics Parameter Types at runtime.</p>
<p>Thats all my suggestion. Am sure you can understand where I am going with this.</p>
<p>OK, bury the little idea, <img src='http://info.dabarobjects.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  but I think Generics is pretty driving some community crazy and something needs to be done about this.</p>
<p>Thank You for your time.</p>
]]></content:encoded>
			<wfw:commentRss>http://info.dabarobjects.com/2008/06/03/some-little-generics-suggestion/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
