<?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"
	>
<channel>
	<title>Comments on: Java Enums</title>
	<atom:link href="http://kennke.org/blog/2007/07/13/java-enums/feed/" rel="self" type="application/rss+xml" />
	<link>http://kennke.org/blog/2007/07/13/java-enums/</link>
	<description>Roman Kennke's ramblings</description>
	<pubDate>Wed, 07 Jan 2009 09:37:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Fred</title>
		<link>http://kennke.org/blog/2007/07/13/java-enums/#comment-50982</link>
		<dc:creator>Fred</dc:creator>
		<pubDate>Mon, 16 Jul 2007 20:37:47 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/13/java-enums/#comment-50982</guid>
		<description>I personally really like enums, and will really like to see more of them.
By the way, one issue you need to be aware of, is that ordinal() and name() of an enum is not a constant (or literal) for the compiler.
What I mean is that "Format.BITMAP.ordinal()" is not equivalent to "public static int BITMAP = 0;". But, in fact internally it is totally equivalent since Format.BITMAP is "public static Format BITMAP = new Format(0,"BITMAP");".
That one reason you cannot use ordinal() and name() in annotation for example.</description>
		<content:encoded><![CDATA[<p>I personally really like enums, and will really like to see more of them.<br />
By the way, one issue you need to be aware of, is that ordinal() and name() of an enum is not a constant (or literal) for the compiler.<br />
What I mean is that &#8220;Format.BITMAP.ordinal()&#8221; is not equivalent to &#8220;public static int BITMAP = 0;&#8221;. But, in fact internally it is totally equivalent since Format.BITMAP is &#8220;public static Format BITMAP = new Format(0,&#8221;BITMAP&#8221;);&#8221;.<br />
That one reason you cannot use ordinal() and name() in annotation for example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haakon Nilsen</title>
		<link>http://kennke.org/blog/2007/07/13/java-enums/#comment-50814</link>
		<dc:creator>Haakon Nilsen</dc:creator>
		<pubDate>Sat, 14 Jul 2007 21:08:03 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/13/java-enums/#comment-50814</guid>
		<description>I see what you mean, and you're right, of course.

By the way, here is a different solution to the same case. It's less powerful than yours with abstract method implementation per member, but perhaps easier to read if it is clear that the getter implementation will be the same for all cases.


public enum Format {

  BITMAP(0),
  XYPIXMAP(1),
  ZPIXMAP(2);

  private int _id;

  Format(int id) { _id = id; }
  public int id() { return _id; }

}


(Hope the formatting went well)</description>
		<content:encoded><![CDATA[<p>I see what you mean, and you&#8217;re right, of course.</p>
<p>By the way, here is a different solution to the same case. It&#8217;s less powerful than yours with abstract method implementation per member, but perhaps easier to read if it is clear that the getter implementation will be the same for all cases.</p>
<p>public enum Format {</p>
<p>  BITMAP(0),<br />
  XYPIXMAP(1),<br />
  ZPIXMAP(2);</p>
<p>  private int _id;</p>
<p>  Format(int id) { _id = id; }<br />
  public int id() { return _id; }</p>
<p>}</p>
<p>(Hope the formatting went well)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: roman</title>
		<link>http://kennke.org/blog/2007/07/13/java-enums/#comment-50701</link>
		<dc:creator>roman</dc:creator>
		<pubDate>Fri, 13 Jul 2007 20:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/13/java-enums/#comment-50701</guid>
		<description>Haakon, yes you're right. But in this particular case, the ID (in the X protocol) really hasn't much to do on the ordinal of the enum. If I ordered them differently, the IDs still must be those that I specified here. Of course, I could have coded up a more useful example, but I was lazy and copy+pasted my code.</description>
		<content:encoded><![CDATA[<p>Haakon, yes you&#8217;re right. But in this particular case, the ID (in the X protocol) really hasn&#8217;t much to do on the ordinal of the enum. If I ordered them differently, the IDs still must be those that I specified here. Of course, I could have coded up a more useful example, but I was lazy and copy+pasted my code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Haakon Nilsen</title>
		<link>http://kennke.org/blog/2007/07/13/java-enums/#comment-50700</link>
		<dc:creator>Haakon Nilsen</dc:creator>
		<pubDate>Fri, 13 Jul 2007 20:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://kennke.org/blog/2007/07/13/java-enums/#comment-50700</guid>
		<description>Your id() approach is a good demonstration of how methods in enums generally work. But readers should be aware that for that particular case, you're really only reimplementing ordinal(), functionality which is inherent to and free with enums. :-)</description>
		<content:encoded><![CDATA[<p>Your id() approach is a good demonstration of how methods in enums generally work. But readers should be aware that for that particular case, you&#8217;re really only reimplementing ordinal(), functionality which is inherent to and free with enums. <img src='http://kennke.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
