<?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: A minor glitch in type-safe enums</title>
	<atom:link href="http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/</link>
	<description>Longer than a blog; shorter than a book</description>
	<lastBuildDate>Wed, 08 Feb 2012 21:45:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Anonymous</title>
		<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/comment-page-1/#comment-776261</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 24 Aug 2011 06:01:12 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/a-minor-glitch-in-type-safe-enums/#comment-776261</guid>
		<description>great post, here is another good link related to &lt;a href=&quot;http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html&quot; rel=&quot;nofollow&quot;&gt; enum in java&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>great post, here is another good link related to <a href="http://javarevisited.blogspot.com/2011/08/enum-in-java-example-tutorial.html" rel="nofollow"> enum in java</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curt Cox</title>
		<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/comment-page-1/#comment-128</link>
		<dc:creator>Curt Cox</dc:creator>
		<pubDate>Sat, 21 Jan 2006 20:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/a-minor-glitch-in-type-safe-enums/#comment-128</guid>
		<description>Throwing a documented exception for an invalid argument at runtime is a good thing.  What&#039;s wrong with catching some of those exceptions at compile time too?</description>
		<content:encoded><![CDATA[<p>Throwing a documented exception for an invalid argument at runtime is a good thing.  What&#8217;s wrong with catching some of those exceptions at compile time too?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Verisimilidude</title>
		<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/comment-page-1/#comment-127</link>
		<dc:creator>Verisimilidude</dc:creator>
		<pubDate>Fri, 20 Jan 2006 22:38:39 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/a-minor-glitch-in-type-safe-enums/#comment-127</guid>
		<description>I&#039;m afraid that I don&#039;t agree that this is a bug (or a problem).  Enums, either from the typesafe enum pattern or from Java 5 are not basic types like int and float that always have some value.  They are object references that are either null or refer to an object of the appropriate type.  That enums in C/C++ always have a value is a side effect of their implementation as int&#039;s.  As soon as you start using the typesafe enum pattern in C++ you are implementing your Enums as pointers and a null pointer is always a possibility.  If the contract for a setter is that it is never passed a null, or the contract for a getter is that it never returns one you must throw an exception for violation of the contract (or change the contract).</description>
		<content:encoded><![CDATA[<p>I&#8217;m afraid that I don&#8217;t agree that this is a bug (or a problem).  Enums, either from the typesafe enum pattern or from Java 5 are not basic types like int and float that always have some value.  They are object references that are either null or refer to an object of the appropriate type.  That enums in C/C++ always have a value is a side effect of their implementation as int&#8217;s.  As soon as you start using the typesafe enum pattern in C++ you are implementing your Enums as pointers and a null pointer is always a possibility.  If the contract for a setter is that it is never passed a null, or the contract for a getter is that it never returns one you must throw an exception for violation of the contract (or change the contract).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curt Cox</title>
		<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/comment-page-1/#comment-122</link>
		<dc:creator>Curt Cox</dc:creator>
		<pubDate>Wed, 18 Jan 2006 19:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/a-minor-glitch-in-type-safe-enums/#comment-122</guid>
		<description>The Nice language has a solution to this problem that would make a nifty addition to Java.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5030232</description>
		<content:encoded><![CDATA[<p>The Nice language has a solution to this problem that would make a nifty addition to Java.<br />
<a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5030232" rel="nofollow">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5030232</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Jablow</title>
		<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/comment-page-1/#comment-121</link>
		<dc:creator>Eric Jablow</dc:creator>
		<pubDate>Wed, 18 Jan 2006 00:02:37 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/a-minor-glitch-in-type-safe-enums/#comment-121</guid>
		<description>Mark your [JDK 1.4] enumerations final also.  As stated, the statement

FontStyle.PLAIN = FontStyle.BOLD;

is legal.  Change that block to read

  public static final FontStyle PLAIN  = new FontStyle(1);
  public static final FontStyle BOLD   = new FontStyle(2);
  public static final FontStyle ITALIC = new FontStyle(3);
  public static final FontStyle BOLD_ITALIC = new FontStyle(4);

Or consider using the Jakarta Commons Lang Enum and ValuedEnum classes.

If you don&#039;t use an aspect, as Jochen suggested, put checks in your set methods, constructors, and readResolve methods.

public void setFontStyle(final FontStyle style) {
  if (style == null) {
    throw new IllegalArgumentException(&quot;Null style&quot;);
  }
  this.style = style;
}
If no object can ever have a null font style, you don&#039;t need to check.</description>
		<content:encoded><![CDATA[<p>Mark your [JDK 1.4] enumerations final also.  As stated, the statement</p>
<p>FontStyle.PLAIN = FontStyle.BOLD;</p>
<p>is legal.  Change that block to read</p>
<p>  public static final FontStyle PLAIN  = new FontStyle(1);<br />
  public static final FontStyle BOLD   = new FontStyle(2);<br />
  public static final FontStyle ITALIC = new FontStyle(3);<br />
  public static final FontStyle BOLD_ITALIC = new FontStyle(4);</p>
<p>Or consider using the Jakarta Commons Lang Enum and ValuedEnum classes.</p>
<p>If you don&#8217;t use an aspect, as Jochen suggested, put checks in your set methods, constructors, and readResolve methods.</p>
<p>public void setFontStyle(final FontStyle style) {<br />
  if (style == null) {<br />
    throw new IllegalArgumentException(&#8220;Null style&#8221;);<br />
  }<br />
  this.style = style;<br />
}<br />
If no object can ever have a null font style, you don&#8217;t need to check.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jochen Bedersdorfer</title>
		<link>http://cafe.elharo.com/blogroll/a-minor-glitch-in-type-safe-enums/comment-page-1/#comment-118</link>
		<dc:creator>Jochen Bedersdorfer</dc:creator>
		<pubDate>Sun, 15 Jan 2006 00:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/java/a-minor-glitch-in-type-safe-enums/#comment-118</guid>
		<description>Just a wild guess, but using an aspect for all method signatures that have a formal parameter with a sub-type of Enum could help.
The aspect would check the parameter for null and throw a suitable expression.</description>
		<content:encoded><![CDATA[<p>Just a wild guess, but using an aspect for all method signatures that have a formal parameter with a sub-type of Enum could help.<br />
The aspect would check the parameter for null and throw a suitable expression.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

