Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0
-
None
-
None
-
Operating System: other
Platform: PC
-
15439
Description
The org.apache.commons.lang.enum.Enum class does not support the following
construct of static inner anonymous sub-classed constants:
public abstract class MyEnum extends Enum {
public static final MyEnum ENUM1 = new MyEnum("enum1") {
public String getValue()
};
public static final MyEnum ENUM2 = new MyEnum("enum2") {
public String getValue()
};
/**
- Constructor.
*/
protected MyEnum(String name) { super(name); }
/**
- Returns a value.
- Creation date: (16/12/2002 13:25:35)
*/
public abstract String getValue();
}
ENUM1 and ENUM2 are assigned anonymous inner class names 'MyEnum$0' and
'MyEnum$1' respectively instead of the super class 'MyEnum' when added to the
list of enumerations kept in the Enum super class via the Enum constructor.
A simple work around is to strip the inner class descriminator off the class
name in the Enum constructor, i.e.
protected Enum(String name) {
super();
if (name == null || name.length() == 0)
iName = name;
// Retrieve class name.
String className = getClass().getName();
// Search for inner class.
int index = className.lastIndexOf('$');
if (index > -1)
Entry entry = (Entry) cEnumClasses.get(className);
if (entry == null)
{ entry = new Entry(); cEnumClasses.put(className, entry); }if (entry.map.containsKey(name))
{ throw new IllegalArgumentException("The Enum name must be unique, '" + name + "' has already been added"); } entry.map.put(name, this);
entry.list.add(this);
}