<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="http://wiki.apidesign.org/skins/common/feed.css?116"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Blogs:AndreiBadea:EnumsInAPIs - Revision history</title>
		<link>http://wiki.apidesign.org/index.php?title=Blogs:AndreiBadea:EnumsInAPIs&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.12.0rc1</generator>
		<lastBuildDate>Sun, 05 Apr 2026 17:29:13 GMT</lastBuildDate>
		<item>
			<title>JaroslavTulach: /* Enums in APIs */</title>
			<link>http://wiki.apidesign.org/index.php?title=Blogs:AndreiBadea:EnumsInAPIs&amp;diff=4397&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Enums in APIs&lt;/span&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 17:25, 9 January 2011&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Enums &lt;/del&gt;in APIs ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;== &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[Enum]]s &lt;/ins&gt;in APIs ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;As Jesse [[Blogs:JesseGlick:OfClassesAndInterfaces|explains]], a client API should generally use final classes, which, among other advantages, are more flexible from the API maintainer's point of view. Particularly, adding a new field or method to a final class is a backward-compatible operation. There is no risk of clash with a method or field added by the user of the API, because the user can't add anything to the class.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;As Jesse [[Blogs:JesseGlick:OfClassesAndInterfaces|explains]], a client API should generally use final classes, which, among other advantages, are more flexible from the API maintainer's point of view. Particularly, adding a new field or method to a final class is a backward-compatible operation. There is no risk of clash with a method or field added by the user of the API, because the user can't add anything to the class.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A particular example of a final class is an enum. It would thus appear that adding new fields to an enum is a backward-compatible operation. Or is it?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;A particular example of a final class is an &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/ins&gt;. It would thus appear that adding new fields to an &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]] &lt;/ins&gt;is a backward-compatible operation. Or is it?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Let's assume the following common code where a switch statements walks over all fields of the enum:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Let's assume the following common code where a switch statements walks over all fields of the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/ins&gt;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Ignore for the moment the fact that such code is better replaced with an instance method on the enum itself. Users tend to come up with creative ways to use your API, or could simply be working around the method missing from the API.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Ignore for the moment the fact that such code is better replaced with an instance method on the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]] &lt;/ins&gt;itself. Users tend to come up with creative ways to use your API, or could simply be working around the method missing from the API.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The &amp;lt;tt&amp;gt;assert false&amp;lt;/tt&amp;gt; statement in the default branch is commonly used to ensure that all fields have been considered. However, if in the next version of the API &amp;lt;tt&amp;gt;FIELD3&amp;lt;/tt&amp;gt; is added to the enum, this code could suddenly start throwing an &amp;lt;tt&amp;gt;AssertionError&amp;lt;/tt&amp;gt;. Code which worked fine in the previous version breaks down in the new version, although it compiles and links successfully. So, adding fields to a public enum is a semantically incompatible change.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The &amp;lt;tt&amp;gt;assert false&amp;lt;/tt&amp;gt; statement in the default branch is commonly used to ensure that all fields have been considered. However, if in the next version of the API &amp;lt;tt&amp;gt;FIELD3&amp;lt;/tt&amp;gt; is added to the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/ins&gt;, this code could suddenly start throwing an &amp;lt;tt&amp;gt;AssertionError&amp;lt;/tt&amp;gt;. Code which worked fine in the previous version breaks down in the new version, although it compiles and links successfully. So, adding fields to a public &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]] &lt;/ins&gt;is a semantically incompatible change.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I don't see a solution which would satisfy both the user and the provider of the API. Either the user doesn't assume that he knows which fields there are in the enum, or the provider freezes the enum once published. The latter seems to restrict the evolution of the API, so it is probably less practical. What do you think?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I don't see a solution which would satisfy both the user and the provider of the API. Either the user doesn't assume that he knows which fields there are in the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]]&lt;/ins&gt;, or the provider freezes the &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[&lt;/ins&gt;enum&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;]] &lt;/ins&gt;once published. The latter seems to restrict the evolution of the API, so it is probably less practical. What do you think?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;--[[User:AndreiBadea|AndreiBadea]] 14:08, 16 July 2008 (UTC)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;--[[User:AndreiBadea|AndreiBadea]] 14:08, 16 July 2008 (UTC)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;comments/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;comments/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</description>
			<pubDate>Sun, 09 Jan 2011 17:25:32 GMT</pubDate>			<dc:creator>JaroslavTulach</dc:creator>			<comments>http://wiki.apidesign.org/wiki/Talk:Blogs:AndreiBadea:EnumsInAPIs</comments>		</item>
		<item>
			<title>AndreiBadea at 14:13, 16 July 2008</title>
			<link>http://wiki.apidesign.org/index.php?title=Blogs:AndreiBadea:EnumsInAPIs&amp;diff=1161&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 14:13, 16 July 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;-&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Ignore for the moment the fact that such code is better replaced with an instance method on the enum itself. &lt;del style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Remember, you don't own the enum, and users &lt;/del&gt;tend to come up with creative ways to use your API.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Ignore for the moment the fact that such code is better replaced with an instance method on the enum itself. &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;Users &lt;/ins&gt;tend to come up with creative ways to use your &lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;API, or could simply be working around the method missing from the &lt;/ins&gt;API.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The &amp;lt;tt&amp;gt;assert false&amp;lt;/tt&amp;gt; statement in the default branch is commonly used to ensure that all fields have been considered. However, if in the next version of the API &amp;lt;tt&amp;gt;FIELD3&amp;lt;/tt&amp;gt; is added to the enum, this code could suddenly start throwing an &amp;lt;tt&amp;gt;AssertionError&amp;lt;/tt&amp;gt;. Code which worked fine in the previous version breaks down in the new version, although it compiles and links successfully. So, adding fields to a public enum is a semantically incompatible change.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;The &amp;lt;tt&amp;gt;assert false&amp;lt;/tt&amp;gt; statement in the default branch is commonly used to ensure that all fields have been considered. However, if in the next version of the API &amp;lt;tt&amp;gt;FIELD3&amp;lt;/tt&amp;gt; is added to the enum, this code could suddenly start throwing an &amp;lt;tt&amp;gt;AssertionError&amp;lt;/tt&amp;gt;. Code which worked fine in the previous version breaks down in the new version, although it compiles and links successfully. So, adding fields to a public enum is a semantically incompatible change.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</description>
			<pubDate>Wed, 16 Jul 2008 14:13:28 GMT</pubDate>			<dc:creator>AndreiBadea</dc:creator>			<comments>http://wiki.apidesign.org/wiki/Talk:Blogs:AndreiBadea:EnumsInAPIs</comments>		</item>
		<item>
			<title>AndreiBadea at 14:08, 16 July 2008</title>
			<link>http://wiki.apidesign.org/index.php?title=Blogs:AndreiBadea:EnumsInAPIs&amp;diff=1160&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;/p&gt;

			&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;tr&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;←Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 14:08, 16 July 2008&lt;/td&gt;
			&lt;/tr&gt;
		&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 23:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 23:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I don't see a solution which would satisfy both the user and the provider of the API. Either the user doesn't assume that he knows which fields there are in the enum, or the provider freezes the enum once published. The latter seems to restrict the evolution of the API, so it is probably less practical. What do you think?&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;I don't see a solution which would satisfy both the user and the provider of the API. Either the user doesn't assume that he knows which fields there are in the enum, or the provider freezes the enum once published. The latter seems to restrict the evolution of the API, so it is probably less practical. What do you think?&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;--[[User:AndreiBadea|AndreiBadea]] 14:08, 16 July 2008 (UTC)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;comments/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;comments/&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</description>
			<pubDate>Wed, 16 Jul 2008 14:08:36 GMT</pubDate>			<dc:creator>AndreiBadea</dc:creator>			<comments>http://wiki.apidesign.org/wiki/Talk:Blogs:AndreiBadea:EnumsInAPIs</comments>		</item>
		<item>
			<title>AndreiBadea: New page: == Enums in APIs ==  As Jesse explains, a client API should generally use final classes, which, among other advantages, are more flexible from t...</title>
			<link>http://wiki.apidesign.org/index.php?title=Blogs:AndreiBadea:EnumsInAPIs&amp;diff=1159&amp;oldid=prev</link>
			<description>&lt;p&gt;New page: == Enums in APIs ==  As Jesse &lt;a href=&quot;/wiki/Blogs:JesseGlick:OfClassesAndInterfaces&quot; title=&quot;Blogs:JesseGlick:OfClassesAndInterfaces&quot;&gt;explains&lt;/a&gt;, a client API should generally use final classes, which, among other advantages, are more flexible from t...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Enums in APIs ==&lt;br /&gt;
&lt;br /&gt;
As Jesse [[Blogs:JesseGlick:OfClassesAndInterfaces|explains]], a client API should generally use final classes, which, among other advantages, are more flexible from the API maintainer's point of view. Particularly, adding a new field or method to a final class is a backward-compatible operation. There is no risk of clash with a method or field added by the user of the API, because the user can't add anything to the class.&lt;br /&gt;
&lt;br /&gt;
A particular example of a final class is an enum. It would thus appear that adding new fields to an enum is a backward-compatible operation. Or is it?&lt;br /&gt;
&lt;br /&gt;
Let's assume the following common code where a switch statements walks over all fields of the enum:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
switch (e) {&lt;br /&gt;
    case FIELD1:&lt;br /&gt;
        return &amp;quot;field1&amp;quot;;&lt;br /&gt;
    case FIELD2:&lt;br /&gt;
        return &amp;quot;field2&amp;quot;;&lt;br /&gt;
    default:&lt;br /&gt;
        assert false;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ignore for the moment the fact that such code is better replaced with an instance method on the enum itself. Remember, you don't own the enum, and users tend to come up with creative ways to use your API.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;assert false&amp;lt;/tt&amp;gt; statement in the default branch is commonly used to ensure that all fields have been considered. However, if in the next version of the API &amp;lt;tt&amp;gt;FIELD3&amp;lt;/tt&amp;gt; is added to the enum, this code could suddenly start throwing an &amp;lt;tt&amp;gt;AssertionError&amp;lt;/tt&amp;gt;. Code which worked fine in the previous version breaks down in the new version, although it compiles and links successfully. So, adding fields to a public enum is a semantically incompatible change.&lt;br /&gt;
&lt;br /&gt;
I don't see a solution which would satisfy both the user and the provider of the API. Either the user doesn't assume that he knows which fields there are in the enum, or the provider freezes the enum once published. The latter seems to restrict the evolution of the API, so it is probably less practical. What do you think?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;comments/&amp;gt;&lt;/div&gt;</description>
			<pubDate>Wed, 16 Jul 2008 14:07:22 GMT</pubDate>			<dc:creator>AndreiBadea</dc:creator>			<comments>http://wiki.apidesign.org/wiki/Talk:Blogs:AndreiBadea:EnumsInAPIs</comments>		</item>
	</channel>
</rss>