United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4401321 : Add type-safe enums to Java

Details
Type:
Enhancement
Submit Date:
2001-01-03
Status:
Resolved
Updated Date:
2003-08-01
Project Name:
JDK
Resolved Date:
2003-08-01
Component:
specification
OS:
windows_nt,generic,windows_95
Sub-Component:
language
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.1.4,1.1.5,1.3.0
Fixed Versions:
5.0 (tiger)

Related Reports
Duplicate:

Sub Tasks

Description
Enumeration types similar to the c++ "enum" are not available in Java. I
searched the bug reports and could not find a match, this may be from a
dilution of other issues related to the terms Enumeration, Enumerated. Along
with the issues and workarounds outlined in

http://www.firstsql.com/java/gotchas/lfside3.htm 

there is no way to use a type checked enumeration in the java "switch" statement with any of the cumbersome
workarounds. I find I use a lot of enumerations with my coding style, it seems
this would also be useful for others programming in Java. I could go on here
but the point I am trying to make is simple.
(Review ID: 115234)
======================================================================

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b14


                                     
2004-06-14
WORK AROUND



Name: boT120536			Date: 01/02/2001


1) Declare a class with a single int or String member variable and a single private constructor.

2) Implement equals().

3) Add several public static final members that are instances of the class.

4) Use these members where you would use enums.

Isn't that easy compared to enums? NOT!!!
======================================================================
                                     
2004-06-11
PUBLIC COMMENTS

...
                                     
2004-06-10
EVALUATION

Enums are just one more form of syntactic sugar that contribute no expressive
power to the language. However, creaping featurism is the way of the world,
and very few people really appreciate the maxim that "less is more". Many
programmers think that "more is more" (ok, so it is intuitive).
Those who want to throw everything including the kitchen sink into
Java can vote for this RFE.
  
gilad.bracha@eng 2001-01-04

The initial evaluation of this bug should not be construed to represent Sun's consensus opinion on the matter.  While we are great fans of the "Typesafe Enum" pattern describe in Item 21 of Bloch's "Effective Java" (Addison-Wesley, 2001), we understand that this pattern's verbosity is a real disadvantage.  We are actively investigating a language feature that would provide all the advantages of this pattern while eliminating the verbosity.

###@###.### 2002-01-09
                                     
2002-01-09



Hardware and Software, Engineered to Work Together