<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>A Code Monkey's Journal</title>
	<atom:link href="http://acoder.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://acoder.wordpress.com</link>
	<description></description>
	<lastBuildDate>Mon, 19 May 2008 20:49:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='acoder.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>A Code Monkey's Journal</title>
		<link>http://acoder.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://acoder.wordpress.com/osd.xml" title="A Code Monkey&#039;s Journal" />
	<atom:link rel='hub' href='http://acoder.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Java method chaining and auto-cast</title>
		<link>http://acoder.wordpress.com/2008/05/19/java-method-chaining-and-auto-cast/</link>
		<comments>http://acoder.wordpress.com/2008/05/19/java-method-chaining-and-auto-cast/#comments</comments>
		<pubDate>Mon, 19 May 2008 20:43:20 +0000</pubDate>
		<dc:creator>adi11235</dc:creator>
				<category><![CDATA[auto-cast]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[method chaining]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://acoder.wordpress.com/?p=12</guid>
		<description><![CDATA[I stumbled into an interesting problem while playing around with java method chaining. Basically, we have an object with a number of properties. We want to assign those properties in an inline manner. Example: MyType t = new MyType(); t.setA("a"); t.setB("b"); t.setC("c"); t.setD("d"); Doing the same through method chaining: MyType t = new MyType().setA("a").setB("b").setC("c").setD("d"); This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=12&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I stumbled into an interesting problem while playing around with java <a href="http://martinfowler.com/dslwip/MethodChaining.html">method chaining</a>.</p>
<p>Basically, we have an object with a number of properties. We want to assign those properties in an inline manner.</p>
<p>Example:<br />
<code>MyType t = new MyType();<br />
t.setA("a");<br />
t.setB("b");<br />
t.setC("c");<br />
t.setD("d");<br />
</code><br />
Doing the same through method chaining:<br />
<code>MyType t = new MyType().setA("a").setB("b").setC("c").setD("d");</code></p>
<p>This is possible because the types of setA(), setB(), &#8230; are the same as MyType.</p>
<p>This is how the implementation of MyType would look:</p>
<p><code>public class MyType {<br />
private String a, b, c, d;</p>
<p>//constructor<br />
public MyType() {<br />
a = ""; b = ""; c = ""; d = "";<br />
return this; //return back the current object<br />
}</p>
<p>public MyType setA(String s) {<br />
a = s;<br />
return this;<br />
}</p>
<p>public MyType setB(String s) {<br />
b = s;<br />
return this;<br />
}</p>
<p>public MyType setC(String s) {<br />
c = s;<br />
return this;<br />
}</p>
<p>public MyType setD(String s) {<br />
d = s;<br />
return this;<br />
}</p>
<p>}<br />
</code><br />
As you see, each method returns its own object at the end of the call so that the other methods can pick up and complete the chain.</p>
<p>Well, this works fine and dandy, but what about derived classes?</p>
<p>The wrong way to do it in java:</p>
<p><code>public class MyDerivedType extends MyType {<br />
private String e;</p>
<p>//constructor<br />
public MyDerivedType () {<br />
super(); //We call the constructor of MyType<br />
e = "";<br />
}</p>
<p>public MyDerivedType setE(String s) {<br />
e = s;<br />
return this;<br />
}<br />
}</code></p>
<p>Use example:<br />
<code>MyDerivedType t = new MyDerivedType().setA("a")...<br />
</code><br />
This throws an exception because it can&#8217;t find a method called setA(). That&#8217;s because the return type of setA remains MyType and it&#8217;s not MyDerivedType.</p>
<p>In order to address this problem, we may do this:</p>
<p><code>MyDerivedType t = (MyDerivedType)(new MyType().setA("a").setB("b"));</code></p>
<p>That is, we use our original type, then we cast the result to MyDerivedType.</p>
<p>That is a bad solution because we have to keep track of our supertypes at all times and that we get the ugliness of casts. The problem is compounded when we need to mix methods of the supertype with methods of derived types:</p>
<p><code>MyDerivedType t = ((MyDerivedType)(new MyType().setA("a").setB("b"))).setE("e");</code></p>
<p>What we have is an inability of java to cast types into their derived classes. That is, we cannot auto-cast from MyType to MyDerivedType:</p>
<p><code>MyDerivedType t = new MyType(); //throws an exception, incompatible types</code></p>
<p>So our solution is to manually override all the methods of the superclass into the derived classes:</p>
<p><code>public class MyDerivedType extends MyType {<br />
private String e;</p>
<p>//constructor<br />
public MyDerivedType () {<br />
super(); //We call the constructor of MyType<br />
e = "";<br />
}</p>
<p>//Override notation to help readability, we can do without it, though<br />
@Override<br />
public MyDerivedType setA(String s) {<br />
return (MyDerivedType)super.setA(s);<br />
}</p>
<p>@Override<br />
public MyDerivedType setB(String s) {<br />
return (MyDerivedType)super.setB(s);<br />
}</p>
<p>@Override<br />
public MyDerivedType setC(String s) {<br />
return (MyDerivedType)super.setC(s);<br />
}</p>
<p>@Override<br />
public MyDerivedType setD(String s) {<br />
return (MyDerivedType)super.setD(s);<br />
}</p>
<p>public MyDerivedType setE(String s) {<br />
e = s;<br />
return this;<br />
}<br />
}</code></p>
<p>With this, we can do:</p>
<p><code>MyDerivedType t = new MyDerivedType().setA("a").setB("b").setC("c").setD("d")<br />
                                                         .setE("e");</code></p>
<p>It&#8217;s all nice and clean and this is how you should do it in Java.</p>
<p>However, there is still a small code duplication problem involved with all this overriding. It would be much easier if Java had auto-cast from derived types. Such a feature would not break type safety since we&#8217;re not casting from arbitrary types.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acoder.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acoder.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acoder.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acoder.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acoder.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acoder.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acoder.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acoder.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acoder.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acoder.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=12&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acoder.wordpress.com/2008/05/19/java-method-chaining-and-auto-cast/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b7e7503321210a73a8e844f78dbcc4dc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adi11235</media:title>
		</media:content>
	</item>
		<item>
		<title>Web services in Netbeans (Video tutorial)</title>
		<link>http://acoder.wordpress.com/2008/05/10/web-services-in-netbeans-video-tutorial/</link>
		<comments>http://acoder.wordpress.com/2008/05/10/web-services-in-netbeans-video-tutorial/#comments</comments>
		<pubDate>Sat, 10 May 2008 12:38:29 +0000</pubDate>
		<dc:creator>adi11235</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://acoder.wordpress.com/?p=11</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=11&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<span style="text-align:center; display: block;"><a href="http://acoder.wordpress.com/2008/05/10/web-services-in-netbeans-video-tutorial/"><img src="http://img.youtube.com/vi/zyRTrccuVAE/2.jpg" alt="" /></a></span>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acoder.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acoder.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acoder.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acoder.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acoder.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acoder.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acoder.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acoder.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acoder.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acoder.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=11&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acoder.wordpress.com/2008/05/10/web-services-in-netbeans-video-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b7e7503321210a73a8e844f78dbcc4dc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adi11235</media:title>
		</media:content>
	</item>
		<item>
		<title>SGML, HTML and XML (Video tutorial)</title>
		<link>http://acoder.wordpress.com/2008/05/09/sgml-html-and-xml-video-tutorial/</link>
		<comments>http://acoder.wordpress.com/2008/05/09/sgml-html-and-xml-video-tutorial/#comments</comments>
		<pubDate>Fri, 09 May 2008 22:27:20 +0000</pubDate>
		<dc:creator>adi11235</dc:creator>
				<category><![CDATA[DTD]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[sgml]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://acoder.wordpress.com/?p=8</guid>
		<description><![CDATA[This old guy does a good job explaining things. Part 1 Part 2<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=8&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This old guy does a good job explaining things.</p>
<p>Part 1</p>
<span style="text-align:center; display: block;"><a href="http://acoder.wordpress.com/2008/05/09/sgml-html-and-xml-video-tutorial/"><img src="http://img.youtube.com/vi/Zdj11zoqwsE/2.jpg" alt="" /></a></span>
<p>Part 2</p>
<span style="text-align:center; display: block;"><a href="http://acoder.wordpress.com/2008/05/09/sgml-html-and-xml-video-tutorial/"><img src="http://img.youtube.com/vi/MQWap_ugQ_s/2.jpg" alt="" /></a></span>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acoder.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acoder.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acoder.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acoder.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acoder.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acoder.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acoder.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acoder.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acoder.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acoder.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=8&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acoder.wordpress.com/2008/05/09/sgml-html-and-xml-video-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b7e7503321210a73a8e844f78dbcc4dc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adi11235</media:title>
		</media:content>
	</item>
		<item>
		<title>XSLT</title>
		<link>http://acoder.wordpress.com/2008/04/20/xslt/</link>
		<comments>http://acoder.wordpress.com/2008/04/20/xslt/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 18:18:13 +0000</pubDate>
		<dc:creator>adi11235</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://acoder.wordpress.com/?p=6</guid>
		<description><![CDATA[A more in-depth description of my recent experience with XSLT will be forthcoming. But until then, gaze your eyes at this: 99bottles.xml 99bottles.xsl (copy both files in one folder and open 99bottles.xml with a web browser)<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=6&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A more in-depth description of my recent experience with XSLT will be forthcoming. But until then, gaze your eyes at this:</p>
<p><a href="http://www.mediafire.com/?wjz2mmxj0ia">99bottles.xml</a></p>
<p><a href="http://www.mediafire.com/?g9nvmom2swg">99bottles.xsl</a></p>
<p>(copy both files in one folder and open 99bottles.xml with a web browser)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/acoder.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/acoder.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/acoder.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/acoder.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/acoder.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/acoder.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/acoder.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/acoder.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/acoder.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/acoder.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=acoder.wordpress.com&amp;blog=3532366&amp;post=6&amp;subd=acoder&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://acoder.wordpress.com/2008/04/20/xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b7e7503321210a73a8e844f78dbcc4dc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">adi11235</media:title>
		</media:content>
	</item>
	</channel>
</rss>
