<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Java Puzzler</title>
	<atom:link href="http://www.simonbuckle.com/2009/03/16/java-puzzler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simonbuckle.com/2009/03/16/java-puzzler/</link>
	<description>Random thoughts for random people</description>
	<lastBuildDate>Mon, 23 Nov 2009 08:06:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Simon Buckle</title>
		<link>http://www.simonbuckle.com/2009/03/16/java-puzzler/comment-page-1/#comment-33427</link>
		<dc:creator>Simon Buckle</dc:creator>
		<pubDate>Fri, 26 Jun 2009 13:29:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.simonbuckle.com/?p=344#comment-33427</guid>
		<description>I found the answer after searching around. As Miles hinted at, there&#039;s some auto-unboxing voodoo going on! The problem, in this example, is the fact that &quot;i&quot; is declared as an Integer; the initial value of &quot;i&quot; is null. When you compare primitives and boxed primitives, the boxed primitive (&quot;i&quot;) is automatically unboxed. If a null object reference is auto-unboxed you get a NullPointerException. The simplest way of &#039;fixing&#039; the example is to change &quot;i&quot; to an int. Or use a different language ...</description>
		<content:encoded><![CDATA[<p>I found the answer after searching around. As Miles hinted at, there&#39;s some auto-unboxing voodoo going on! The problem, in this example, is the fact that &#8220;i&#8221; is declared as an Integer; the initial value of &#8220;i&#8221; is null. When you compare primitives and boxed primitives, the boxed primitive (&#8220;i&#8221;) is automatically unboxed. If a null object reference is auto-unboxed you get a NullPointerException. The simplest way of &#39;fixing&#39; the example is to change &#8220;i&#8221; to an int. Or use a different language &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon Buckle</title>
		<link>http://www.simonbuckle.com/2009/03/16/java-puzzler/comment-page-1/#comment-33393</link>
		<dc:creator>Simon Buckle</dc:creator>
		<pubDate>Fri, 26 Jun 2009 06:29:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.simonbuckle.com/?p=344#comment-33393</guid>
		<description>I found the answer after searching around. As Miles hinted at, there&#039;s some auto-unboxing voodoo going on! The problem, in this example, is the fact that &quot;i&quot; is declared as an Integer; the initial value of &quot;i&quot; is null. When you compare primitives and boxed primitives, the boxed primitive (&quot;i&quot;) is automatically unboxed. If a null object reference is auto-unboxed you get a NullPointerException. The simplest way of &#039;fixing&#039; the example is to change &quot;i&quot; to an int. Or use a different language ...</description>
		<content:encoded><![CDATA[<p>I found the answer after searching around. As Miles hinted at, there&#39;s some auto-unboxing voodoo going on! The problem, in this example, is the fact that &#8220;i&#8221; is declared as an Integer; the initial value of &#8220;i&#8221; is null. When you compare primitives and boxed primitives, the boxed primitive (&#8220;i&#8221;) is automatically unboxed. If a null object reference is auto-unboxed you get a NullPointerException. The simplest way of &#39;fixing&#39; the example is to change &#8220;i&#8221; to an int. Or use a different language &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob Knippen</title>
		<link>http://www.simonbuckle.com/2009/03/16/java-puzzler/comment-page-1/#comment-33392</link>
		<dc:creator>Bob Knippen</dc:creator>
		<pubDate>Thu, 25 Jun 2009 23:28:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.simonbuckle.com/?p=344#comment-33392</guid>
		<description>I&#039;m no java expert, but I think the reason the compiler doesn&#039;t pick up an uninitialized static variable is that it could be initialized almost anywhere. That is, unlike a local (where the initialization would have to be in the same method), a static is available for anybody to initialize. When I say anybody, I mean, other methods in the class, in subclasses, or in your case (since the variable is not private) other unrelated classes. As crazy as it might seem, some other class could do: Unbelievable.i = 42; before calling the main method and the code word work just fine.</description>
		<content:encoded><![CDATA[<p>I&#39;m no java expert, but I think the reason the compiler doesn&#39;t pick up an uninitialized static variable is that it could be initialized almost anywhere. That is, unlike a local (where the initialization would have to be in the same method), a static is available for anybody to initialize. When I say anybody, I mean, other methods in the class, in subclasses, or in your case (since the variable is not private) other unrelated classes. As crazy as it might seem, some other class could do: Unbelievable.i = 42; before calling the main method and the code word work just fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sbuckle</title>
		<link>http://www.simonbuckle.com/2009/03/16/java-puzzler/comment-page-1/#comment-33236</link>
		<dc:creator>sbuckle</dc:creator>
		<pubDate>Tue, 17 Mar 2009 16:39:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.simonbuckle.com/?p=344#comment-33236</guid>
		<description>Thanks Miles. I&#039;ll take a look. Have just ordered the latest edition of Effective Java. &lt;br&gt;&lt;br&gt;I noticed that Joshua Bloch has another book called Java Puzzlers. I had a look at it and it seems to go into way more detail than I ever want to know about Java!</description>
		<content:encoded><![CDATA[<p>Thanks Miles. I&#39;ll take a look. Have just ordered the latest edition of Effective Java. </p>
<p>I noticed that Joshua Bloch has another book called Java Puzzlers. I had a look at it and it seems to go into way more detail than I ever want to know about Java!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miles Barr</title>
		<link>http://www.simonbuckle.com/2009/03/16/java-puzzler/comment-page-1/#comment-33219</link>
		<dc:creator>Miles Barr</dc:creator>
		<pubDate>Tue, 17 Mar 2009 01:12:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.simonbuckle.com/?p=344#comment-33219</guid>
		<description>In the first example something else could have set a value to i. In fact it does get initialised, to null. All fields are initialised, objects to null, numbers to 0, booleans to false, etc.:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;http://www.artima.com/designtechniques/initialization2.html&quot; rel=&quot;nofollow&quot;&gt;http://www.artima.com/designtechniques/initiali...&lt;/a&gt;&lt;br&gt;&lt;br&gt;Local variables aren&#039;t intialised by default.&lt;br&gt;&lt;br&gt;The current compiler does some more analysis, e.g. :&lt;br&gt;&lt;br&gt;Integer i = null;&lt;br&gt;if (i == 42)&lt;br&gt;  System.out.println(&quot;Unbelievable&quot;);&lt;br&gt;&lt;br&gt;shouldn&#039;t compile either, but I think earlier Java compilers would allow it. If it does compile there could be some auto unboxing voodoo going on.&lt;br&gt;&lt;br&gt;I don&#039;t know how much program analysis the current Java compiler does, but it can always do more. Take a look at:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.162&quot; rel=&quot;nofollow&quot;&gt;http://citeseerx.ist.psu.edu/viewdoc/summary?do...&lt;/a&gt;&lt;br&gt;&lt;br&gt;and various lint tools like:&lt;br&gt;&lt;br&gt;&lt;a href=&quot;http://findbugs.sourceforge.net/&quot; rel=&quot;nofollow&quot;&gt;http://findbugs.sourceforge.net/&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>In the first example something else could have set a value to i. In fact it does get initialised, to null. All fields are initialised, objects to null, numbers to 0, booleans to false, etc.:</p>
<p><a href="http://www.artima.com/designtechniques/initialization2.html" rel="nofollow"></a><a href="http://www.artima.com/designtechniques/initiali.." rel="nofollow">http://www.artima.com/designtechniques/initiali..</a>.</p>
<p>Local variables aren&#39;t intialised by default.</p>
<p>The current compiler does some more analysis, e.g. :</p>
<p>Integer i = null;<br />if (i == 42)<br />  System.out.println(&#8220;Unbelievable&#8221;);</p>
<p>shouldn&#39;t compile either, but I think earlier Java compilers would allow it. If it does compile there could be some auto unboxing voodoo going on.</p>
<p>I don&#39;t know how much program analysis the current Java compiler does, but it can always do more. Take a look at:</p>
<p><a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.162" rel="nofollow"></a><a href="http://citeseerx.ist.psu.edu/viewdoc/summary?do.." rel="nofollow">http://citeseerx.ist.psu.edu/viewdoc/summary?do..</a>.</p>
<p>and various lint tools like:</p>
<p><a href="http://findbugs.sourceforge.net/" rel="nofollow">http://findbugs.sourceforge.net/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
