<?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: Instantiate an innerclass from the main constructor does not works.</title>
	<atom:link href="http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/feed/" rel="self" type="application/rss+xml" />
	<link>http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/</link>
	<description>A blog on my experiences in programming, work, and life!</description>
	<lastBuildDate>Wed, 08 Feb 2012 23:31:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Michael</title>
		<link>http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/comment-page-1/#comment-1604</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Wed, 04 Mar 2009 11:28:30 +0000</pubDate>
		<guid isPermaLink="false">http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/#comment-1604</guid>
		<description>Hey,

Dit is een pure gok he, dus schiet me nie dood, geen programmas meer om het te testen :

public class Main
{
	public static void main(String[] args)
	{
		Test t = this.new Test();
 
		System.out.println(t.getInt());
	}
 
	private class Test
	{
		public Test()
		{
		}
 
		public int getInt()
		{
			return 5;
		}
	}
}</description>
		<content:encoded><![CDATA[<p>Hey,</p>
<p>Dit is een pure gok he, dus schiet me nie dood, geen programmas meer om het te testen :</p>
<p>public class Main<br />
{<br />
	public static void main(String[] args)<br />
	{<br />
		Test t = this.new Test();</p>
<p>		System.out.println(t.getInt());<br />
	}</p>
<p>	private class Test<br />
	{<br />
		public Test()<br />
		{<br />
		}</p>
<p>		public int getInt()<br />
		{<br />
			return 5;<br />
		}<br />
	}<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan</title>
		<link>http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/comment-page-1/#comment-1602</link>
		<dc:creator>Jan</dc:creator>
		<pubDate>Tue, 03 Mar 2009 23:58:32 +0000</pubDate>
		<guid isPermaLink="false">http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/#comment-1602</guid>
		<description>Well the solution is to make it a static inner class so like this

public class Main  {
public static class Test {
}
}

but then Test cannot access Main&#039;s variables anymore.</description>
		<content:encoded><![CDATA[<p>Well the solution is to make it a static inner class so like this</p>
<p>public class Main  {<br />
public static class Test {<br />
}<br />
}</p>
<p>but then Test cannot access Main&#8217;s variables anymore.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kristof</title>
		<link>http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/comment-page-1/#comment-1601</link>
		<dc:creator>Kristof</dc:creator>
		<pubDate>Tue, 03 Mar 2009 23:55:10 +0000</pubDate>
		<guid isPermaLink="false">http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/#comment-1601</guid>
		<description>@Jan no that does not work, (I tried it), and it actually makes sense, there is no &#039;this&#039; variable in a static context.

So we&#039;re still looking for a solution over here :)</description>
		<content:encoded><![CDATA[<p>@Jan no that does not work, (I tried it), and it actually makes sense, there is no &#8216;this&#8217; variable in a static context.</p>
<p>So we&#8217;re still looking for a solution over here <img src='http://kristofmattei.be/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan</title>
		<link>http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/comment-page-1/#comment-1600</link>
		<dc:creator>Jan</dc:creator>
		<pubDate>Tue, 03 Mar 2009 22:04:53 +0000</pubDate>
		<guid isPermaLink="false">http://kristofmattei.be/2009/03/03/java-instantiate-an-innerclass-from-the-main-constructor-does-not-works/#comment-1600</guid>
		<description>The problem is that Java and C# handle their inner classes differently. Java inner classes have access to the members of the enclosing class. Thus you cannot construct the Main.Test class without having an instance of Main, and as you are in a static function you have no such reference, and this is what the error: &quot;non-static variable this cannot be referenced from a static context&quot; is telling you. 

Test t = new Test() can be rewritten as Test t = this.new Test()

I hope this makes things clear.</description>
		<content:encoded><![CDATA[<p>The problem is that Java and C# handle their inner classes differently. Java inner classes have access to the members of the enclosing class. Thus you cannot construct the Main.Test class without having an instance of Main, and as you are in a static function you have no such reference, and this is what the error: &#8220;non-static variable this cannot be referenced from a static context&#8221; is telling you. </p>
<p>Test t = new Test() can be rewritten as Test t = this.new Test()</p>
<p>I hope this makes things clear.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

