未完 Java: enum 枚举

 
http://stackoverflow.com/questions/9850525/whats-the-use-of-enum-in-java
引用
An enum is an ordinary class with a predefined and enumerable set of instances.
So, if you know in advance (in compile-time) how many instances a class will have and if the instances are easily enumerable, then use an enum.


JLS 8.9. Enums:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9
引用
The direct superclass of an enum type named E is Enum<E>
Java Tutorials - Enum Types:
http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
引用
All enums implicitly extend java.lang.Enum. Since Java does not support multiple inheritance, an enum cannot extend anything else.(但是可以 implements 接口)


将一个带参 enum 的参数值作为 Spring applicationContext.xml 中 util:map or util:set 的 elements:
http://stackoverflow.com/questions/14072314/inject-the-value-of-an-enum-into-a-property-using-spring
引用
enum 类:
public class EmailEntity {
    public enum EmailTags {

        SOME_THING("some thing"), //放入 util-set bean 中
        ANOTHER_THING("another thing"),
        YET_ANOTHER_THING("yet another thing"); //放入 util-set bean 中

        private final String value;

        private EmailTags(String value) { this.value = value; }

        public String getValue() { return value; }

    }
}
applicationContext.xml:
  <util:set id="enumValueSet" set-class="java.util.HashSet">
    <bean factory-bean="someThing" factory-method="getValue" />
    <bean factory-bean="yetAnotherThing" factory-method="getValue" />
  </util:set>

  <util:constant id="someThing" static-field="com.package.EmailEntity$EmailTags.SOME_THING" />
  <util:constant id="yetAnotherThing" static-field="com.package.EmailEntity$EmailTags.YET_ANOTHER_THING" />
使用 util-set bean:
@Service("xService")
public class XServiceImpl implements XService {
    @Resource
    private Set<String> enumValueSet;
}
util-set enumValueSet 中放入的是两个字符串:
some thing
yet another thing



getNext & cyclic getNext in Java Enum:
http://digitaljoel.nerd-herders.com/2011/04/05/get-the-next-value-in-a-java-enum/


srcs:
java enum(枚举)使用详解 + 总结:
http://www.cnblogs.com/hemingwang0902/archive/2011/12/29/2306263.html
常量接口 vs 枚举常量类:
http://caerun.iteye.com/blog/458439

你可能感兴趣的:(enum,枚举)