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

<channel>
	<title>Alessandro Stella - Appunti di informatica &#187; nested class</title>
	<atom:link href="http://www.alessandrostella.it/tag/nested-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alessandrostella.it</link>
	<description>Appunti sparsi di informatica</description>
	<lastBuildDate>Thu, 09 Sep 2010 15:20:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Java 1.6, nested type e inner classes</title>
		<link>http://www.alessandrostella.it/java/2010/02/java-1-6-nested-type-e-inner-classes/</link>
		<comments>http://www.alessandrostella.it/java/2010/02/java-1-6-nested-type-e-inner-classes/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 16:13:29 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[anonymous class]]></category>
		<category><![CDATA[inner class]]></category>
		<category><![CDATA[nested class]]></category>

		<guid isPermaLink="false">http://www.alessandrostella.it/?p=645</guid>
		<description><![CDATA[Che confusione! Sui tipi annidati (nested type) e la classi interne (inner classes) in giro per la rete ci sono scritte un sacco di fregnacce! Probabilmente perché la SUN, a partire dalla versione 1.4 di java, ha fatto un po&#8217; di casini con la nomenclatura, modificando il significato di alcuni termini. Comunque sia, ora proviamo [...]]]></description>
			<content:encoded><![CDATA[<p>Che confusione!<br />
Sui tipi annidati (nested type) e la classi interne (inner classes) in giro per la rete ci sono scritte un sacco di fregnacce! Probabilmente perché la SUN, a partire dalla versione 1.4 di java, ha fatto un po&#8217; di casini con la nomenclatura, modificando il significato di alcuni termini. Comunque sia, ora proviamo a fare chiarezza.<br />
Per prima cosa mettiamo in chiaro un concetto: le definizioni in informatica si danno e si usano in inglese. Ci si può riferire al corrispondente termine italiano per meglio comprendere di cosa si parla, ma è l&#8217;inglese che rende univoco un concetto o una definizione.<br />
Torniamo quindi all&#8217;Università e alle definizioni <img src='http://www.alessandrostella.it/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Definizione:<br />
Con il termine <strong>nested type</strong> (tipi annidati) si intende indicare:</p>
<ul>
<li>nested classes</li>
<li>nested enums</li>
<li>nested interfaces</li>
</ul>
<p>Definizione:<br />
Con il termine <strong>nested class</strong> (classe annidata) si intende una classe dichiarata all&#8217;interno di un&#8217;altra classe.<br />
Allo stesso modo si definisono le nested enum e le nested interface.<br />
Ci sono 4 tipi di nested classes:</p>
<ol>
<li>static member classes, enums e interfaces</li>
<li><a href="http://www.alessandrostella.it/java/2010/04/java-non-static-member-class/">non-static member classes</a></li>
<li><a href="http://www.alessandrostella.it/java/2010/04/java-local-classes/">local classes</a></li>
<li><a href="http://www.alessandrostella.it/java/2010/04/java-anonymous-classes/">anonymous classes</a></li>
</ol>
<p>Definizione:<br />
Con il termine <strong>inner class</strong> (classe interna) si indica una qualsiasi nested class purché NON di tipo 1 (vedi definizione precedente).</p>
<p>Facciamo un esempio commentato a dovere:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:100%;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> Alessandro <span style="color: #009900;">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (1) Top level class</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> SMC <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">/*...*/</span><span style="color: #009900;">&#125;</span>&nbsp; <span style="color: #666666; font-style: italic;">// (2) Static member class</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">interface</span> SMI <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">/*...*/</span><span style="color: #009900;">&#125;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (3) Static member interface</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> NSMC <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">/*...*/</span><span style="color: #009900;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (4) Non-static member (inner) class</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">void</span> nsm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> NSLC <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">/*...*/</span><span style="color: #009900;">&#125;</span>&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (5) Local (inner) class in non-static context</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> sm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> SLC <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">/*...*/</span><span style="color: #009900;">&#125;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (6) Local (inner) class in static context</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; SMC nsf <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SMC<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (7) Anonymous (inner) class in non-static context</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*...*/</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">static</span> SMI sf <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SMI<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// (8) Anonymous (inner) class in static context</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/*...*/</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">enum</span> SME <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">/*...*/</span><span style="color: #009900;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// (9) Static member enum</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.alessandrostella.it/java/2010/02/java-1-6-nested-type-e-inner-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
