[ http://issues.apache.org/jira/browse/LANG-258?page=comments#action_12443958 ] Henri Yandell commented on LANG-258: ------------------------------------
svn ci -m "Taking a stab at adding information on a Lang and Java 5.0 enum comparison" src/java/org/apache/commons/lang/enums/Enum.java Sending src/java/org/apache/commons/lang/enums/Enum.java Transmitting file data . Committed revision 466285. Namely: * <h4>Lang Enums and Java 5.0 Enums</h4> * * <p>Enums were added to Java in Java 5.0. The main differences between Lang's * implementation and the new official JDK implementation are: </p> * <ul> * <li>The standard Enum is a not just a superclass, but is a type baked into the * language. </li> * <li>The standard Enum does not support extension, so the standard methods that * are provided in the Lang enum are not available. </li> * <li>Lang mandates a String name, whereas the standard Enum uses the class * name as its name. getName() changes to name(). </li> * </ul> * * <p>Generally people should use the standard Enum. Migrating from the Lang * enum to the standard Enum is not as easy as it might be due to the lack of * class inheritence in standard Enums. This means that it's not possible * to provide a 'super-enum' which could provide the same utility methods * that the Lang enum does. The following utility class is a Java 5.0 * version of our EnumUtils class and provides those utility methods. </p> * * <pre> * import java.util.*; * * public class EnumUtils { * * public static Enum getEnum(Class enumClass, String token) { * return Enum.valueOf(enumClass, token); * } * * public static Map getEnumMap(Class enumClass) { * HashMap map = new HashMap(); * Iterator itr = EnumUtils.iterator(enumClass); * while(itr.hasNext()) { * Enum enm = (Enum) itr.next(); * map.put( enm.name(), enm ); * } * return map; * } * * public static List getEnumList(Class enumClass) { * return new ArrayList( EnumSet.allOf(enumClass) ); * } * * public static Iterator iterator(Class enumClass) { * return EnumUtils.getEnumList(enumClass).iterator(); * } * } * </pre> > Enum JavaDoc: 1) outline 5.0 native Enum migration 2) warn not to use the > switch() , 3) point out approaches for persistence and gui > ------------------------------------------------------------------------------------------------------------------------------------ > > Key: LANG-258 > URL: http://issues.apache.org/jira/browse/LANG-258 > Project: Commons Lang > Issue Type: Improvement > Affects Versions: 2.1 > Environment: all > Reporter: Ralf Hauser > Fix For: 2.3 > > > http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/enums/Enum.html > is great! > Now that Jdk5.0 has its own approach for type-safe enums, would it be great > to provide a few sentences > - whether they simply should co-habit? > - how one would best migrate? > - where the concepts are different > Also, it would be great to provide some hints how to work on the with a > MVC/GUI framework - see SB-20. > also, > http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/enums/ValuedEnum.html > has a minor typo > it says "doSomething(JavaVersion", but should say > "doSomething(JavaVersionEnum" > also, it should contain a big warning that by using switch(), one opens up > for type-unsafety! -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]