<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4736747065114697290</id><updated>2011-04-22T06:14:48.318+03:00</updated><title type='text'>My Tech Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tavi-mytechblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736747065114697290/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://tavi-mytechblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tavi</name><uri>http://www.blogger.com/profile/05323271180930483573</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://bp2.blogger.com/_wiardV93Kgo/R5OqrSAArSI/AAAAAAAAA4s/VjtqILZEzYg/S220/Me.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4736747065114697290.post-6354621722389619319</id><published>2008-03-03T23:12:00.004+02:00</published><updated>2008-04-23T13:28:26.979+03:00</updated><title type='text'>Java 5 for and Enumerations: don't stop, add type tokens</title><content type='html'>Some time ago I bumped into &lt;a href="http://stephan.reposita.org/archives/2007/11/03/use-java-5-for-with-an-enumertion/"&gt;this&lt;/a&gt; blog post that presented an &lt;a href="http://en.wikipedia.org/wiki/Adapter_pattern"&gt;Adapter&lt;/a&gt; from &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Enumeration.html"&gt;Enumeration&lt;/a&gt; to &lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Iterable.html"&gt;Iterable&lt;/a&gt;/&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Iterator.html"&gt;Iterator&lt;/a&gt;. It was so simple and yet incredibly useful. How could I have not though of this? Imagine my &lt;a href="http://www.urbandictionary.com/define.php?term=dooh"&gt;'dooh'&lt;/a&gt; moment, especially since I was working for some time now with an API that's exclusively based on Enumerations (I guess they are keen on extreme backwards compatibility - no iterators, not one!) and I was using JDK 1.5...&lt;br /&gt;&lt;br /&gt;However, I think we can push things a little bit further (well, we can always do this, can't we?). Follow me on this one.&lt;br /&gt;&lt;br /&gt;One of the main applications of the Adapter design pattern is to support legacy code or code that we can't change (like the one in vendor/third-party libs) but we need/would like it to conform to a certain interface (Iterable in our case).&lt;br /&gt;&lt;br /&gt;Now, if we think a bit, most (if not all) of the legacy code based on Enumerations is not likely to support Generics either so simply using iterate() over raw Enumerations would end up in a bunch of unchecked warnings. We could leave it this way or we could add &lt;span style="font-style: italic;"&gt;@SupressWarnings("unchecked")&lt;/span&gt; (which is not really a satisfying solution, &lt;a href="http://developers.sun.com/learning/javaoneonline/2007/pdf/TS-2689.pdf"&gt;is it&lt;/a&gt;?).&lt;br /&gt;&lt;br /&gt;What we could do to improve things a little is to add an extra method (see the code below), similar to iterate(), that takes an additional type token as the second argument representing the &lt;span style="font-style: italic;"&gt;expected&lt;/span&gt; type of the elements of the adapted Enumeration (one could read more about type tokens in Gilad Bracha's really nice Generics &lt;a href="http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf"&gt;tutorial&lt;/a&gt;). I've also taken the liberty to rename the methods to &lt;span style="font-style: italic;"&gt;in()&lt;/span&gt; to come closer to another nice topic - &lt;a href="http://martinfowler.com/bliki/FluentInterface.html"&gt;fluent interfaces&lt;/a&gt; that is.&lt;br /&gt;&lt;pre   style="color: rgb(0, 139, 255); background-color: rgb(0, 0, 53);font-family:'Bitstream Vera Sans Mono';font-size:10pt;"&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 01 &lt;/span&gt;&lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;package&lt;/span&gt; ro&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;thon&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;util&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 02 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 03 &lt;/span&gt;&lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;import static&lt;/span&gt; ro&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;thon&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;util&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;Assert&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;notNull&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 04 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 05 &lt;/span&gt;&lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;import&lt;/span&gt; java&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;util&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(19, 216, 239);"&gt;Enumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 06 &lt;/span&gt;&lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;import&lt;/span&gt; java&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;util&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(19, 216, 239);"&gt;Iterator&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 07 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 08 &lt;/span&gt;&lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public final class&lt;/span&gt; Iterators &lt;span style="color: rgb(255, 255, 255);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 09 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 10 &lt;/span&gt;    &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;Iterators&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;() {&lt;/span&gt; &lt;span style="color: rgb(255, 187, 0); font-style: italic;"&gt;/* prevent any instantiation... */&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 11 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 12 &lt;/span&gt;    &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;private static final class&lt;/span&gt; IterableEnumeration&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(136, 136, 136);"&gt;&lt;/span&gt;&lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;implements&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Iterable&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Iterator&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 14 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 15 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Enumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;?&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 16 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 17 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;private&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Class&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;? &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;extends&lt;/span&gt; E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; klass&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 18 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 19 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;IterableEnumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(19, 216, 239);"&gt;Enumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;?&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Class&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;?&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 20 &lt;/span&gt;                                   &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;extends&lt;/span&gt; E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; klass&lt;span style="color: rgb(255, 255, 255);"&gt;) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 21 &lt;/span&gt;            &lt;span style="color: rgb(255, 255, 255);"&gt;notNull&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;"non-null enumeration expected"&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 22 &lt;/span&gt;            &lt;span style="color: rgb(255, 255, 255);"&gt;notNull&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;klass&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;"non-null type token expected"&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 23 &lt;/span&gt;            &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;enumeration &lt;span style="color: rgb(255, 255, 255);"&gt;=&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 24 &lt;/span&gt;            &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;klass &lt;span style="color: rgb(255, 255, 255);"&gt;=&lt;/span&gt; klass&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 25 &lt;/span&gt;        &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 26 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 27 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;IterableEnumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(19, 216, 239);"&gt;Enumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;? &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;extends&lt;/span&gt; E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 28 &lt;/span&gt;            &lt;span style="color: rgb(255, 255, 255);"&gt;notNull&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;"non-null enumeration expected"&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 29 &lt;/span&gt;            &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;this&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;enumeration &lt;span style="color: rgb(255, 255, 255);"&gt;=&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 30 &lt;/span&gt;        &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 31 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 32 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Iterator&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;iterator&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;() {&lt;/span&gt; &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;return this&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 33 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 34 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(225, 231, 47);"&gt;boolean&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;hasNext&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;() {&lt;/span&gt; &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;return&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;hasMoreElements&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(); }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 35 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 36 &lt;/span&gt;        @&lt;span style="color: rgb(255, 255, 255);"&gt;SuppressWarnings&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;"unchecked"&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 37 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public&lt;/span&gt; E &lt;span style="color: rgb(255, 255, 255);"&gt;next&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 38 &lt;/span&gt;            &lt;span style="color: rgb(19, 216, 239);"&gt;Object&lt;/span&gt; next &lt;span style="color: rgb(255, 255, 255);"&gt;=&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;nextElement&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 39 &lt;/span&gt;            &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;return&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;klass &lt;span style="color: rgb(255, 255, 255);"&gt;==&lt;/span&gt; null&lt;span style="color: rgb(255, 255, 255);"&gt;)&lt;/span&gt; ? &lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;)&lt;/span&gt; next &lt;span style="color: rgb(255, 255, 255);"&gt;:&lt;/span&gt; klass&lt;span style="color: rgb(255, 255, 255);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;cast&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;next&lt;span style="color: rgb(255, 255, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 40 &lt;/span&gt;        &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 41 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 42 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public&lt;/span&gt; &lt;span style="color: rgb(225, 231, 47);"&gt;void&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;remove&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;() {&lt;/span&gt; &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;throw new&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;UnsupportedOperationException&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(); }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 43 &lt;/span&gt;    &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 44 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 45 &lt;/span&gt;    &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public static&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Iterable&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(19, 216, 239);"&gt;Enumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;?&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 46 &lt;/span&gt;                                     &lt;span style="color: rgb(19, 216, 239);"&gt;Class&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;? &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;extends&lt;/span&gt; E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; klass&lt;span style="color: rgb(255, 255, 255);"&gt;) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 47 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;return new&lt;/span&gt; IterableEnumeration&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;(&lt;/span&gt;enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;,&lt;/span&gt; klass&lt;span style="color: rgb(255, 255, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 48 &lt;/span&gt;    &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 49 &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 50 &lt;/span&gt;    &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;public static&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(19, 216, 239);"&gt;Iterable&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;span style="color: rgb(255, 255, 255);"&gt;in&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(19, 216, 239);"&gt;Enumeration&lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;? &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;extends&lt;/span&gt; E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;&lt;/span&gt; enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 51 &lt;/span&gt;        &lt;span style="color: rgb(248, 197, 11); font-weight: bold;"&gt;return new&lt;/span&gt; IterableEnumeration&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;lt;&lt;/span&gt;E&lt;span style="color: rgb(255, 255, 255);"&gt;&amp;gt;(&lt;/span&gt;enumeration&lt;span style="color: rgb(255, 255, 255);"&gt;);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 52 &lt;/span&gt;    &lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(136, 136, 136);"&gt; 53 &lt;/span&gt;&lt;span style="color: rgb(255, 255, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Now, calling the second version of &lt;span style="font-style: italic;"&gt;in()&lt;/span&gt; eliminates those (really) annoying unchecked warnings.&lt;br /&gt;&lt;br /&gt;Note that this is &lt;span style="font-style: italic;"&gt;not entirely&lt;/span&gt; type safe, since we could easily pass a raw Enumeration of another type or (relying too much on code completion) we could pass another class token (with a similar name) &lt;span style="font-style: italic;"&gt;but&lt;/span&gt; at least we got rid of the pesky warnings.&lt;br /&gt;&lt;br /&gt;Anyway, great blog Stephan, thanks again. Me friend! :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736747065114697290-6354621722389619319?l=tavi-mytechblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tavi-mytechblog.blogspot.com/feeds/6354621722389619319/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736747065114697290&amp;postID=6354621722389619319' title='1 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736747065114697290/posts/default/6354621722389619319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736747065114697290/posts/default/6354621722389619319'/><link rel='alternate' type='text/html' href='http://tavi-mytechblog.blogspot.com/2008/03/java-5-for-and-enumerations-dont-stop.html' title='Java 5 for and Enumerations: don&apos;t stop, add type tokens'/><author><name>Tavi</name><uri>http://www.blogger.com/profile/05323271180930483573</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://bp2.blogger.com/_wiardV93Kgo/R5OqrSAArSI/AAAAAAAAA4s/VjtqILZEzYg/S220/Me.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4736747065114697290.post-256052208778324810</id><published>2008-01-20T21:20:00.000+02:00</published><updated>2008-01-20T22:02:44.793+02:00</updated><title type='text'>Ave Mundi!</title><content type='html'>&lt;div style="text-align: justify;"&gt;I finally decided to listen to one of my good friends and stop spamming him with technology-related, ranting e-mails and create some blog entries... (so here I am Luci, with my first real blog :))&lt;br /&gt;&lt;br /&gt;This blog will be _mostly_ about software development, since this is my current hobby, and my current means to make a living (ain't I a lucky one...). To be more specific, my current interests are in the fields of Design Patterns (and how to stay away from them), typing (in general - static, dynamic, generics), Java, Ruby and other related stuff (I guess this is the most generic phrase I can find right now :)).&lt;br /&gt;&lt;br /&gt;The main reason I started this blog is for me to learn more things related to software development (could one imagine a more selfish reason?), but I really, really hope others will find the things I (and the repliers) discuss here helpful too.&lt;br /&gt;&lt;br /&gt;P.S. The thing about how to stay away from Design Patterns - what I really meant was how to learn to use them when appropriate and make the most out of them :) ...&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736747065114697290-256052208778324810?l=tavi-mytechblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://tavi-mytechblog.blogspot.com/feeds/256052208778324810/comments/default' title='Postare comentarii'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736747065114697290&amp;postID=256052208778324810' title='1 comentarii'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736747065114697290/posts/default/256052208778324810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736747065114697290/posts/default/256052208778324810'/><link rel='alternate' type='text/html' href='http://tavi-mytechblog.blogspot.com/2008/01/ave-mundi.html' title='Ave Mundi!'/><author><name>Tavi</name><uri>http://www.blogger.com/profile/05323271180930483573</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='31' src='http://bp2.blogger.com/_wiardV93Kgo/R5OqrSAArSI/AAAAAAAAA4s/VjtqILZEzYg/S220/Me.jpg'/></author><thr:total>1</thr:total></entry></feed>
