Enum 的values() 方法应该是在编译的过程中动态生成的。
如下代码所示:
- //申明一个ENUM
- enum SimpleEnum {
- ONE,TWO;
- }
- //经过jad反编译后的结果
- final class SimpleEnum extends Enum
- {
- private SimpleEnum(String s, int i)
- {
- super(s, i);
- }
- public static SimpleEnum[] values()
- {
- SimpleEnum asimpleenum[];
- int i;
- SimpleEnum asimpleenum1[];
- System.arraycopy(asimpleenum = ENUM$VALUES, 0, asimpleenum1 = new SimpleEnum[i = asimpleenum.length], 0, i);
- return asimpleenum1;
- }
- public static SimpleEnum valueOf(String s)
- {
- return (SimpleEnum)Enum.valueOf(uc/classtest/SimpleEnum, s);
- }
- public static final SimpleEnum ONE;
- public static final SimpleEnum TWO;
- private static final SimpleEnum ENUM$VALUES[];
- static
- {
- ONE = new SimpleEnum("ONE", 0);
- TWO = new SimpleEnum("TWO", 1);
- ENUM$VALUES = (new SimpleEnum[] {
- ONE, TWO
- });
- }
- }
复制代码 |