枚举

2018-09-24  本文已影响12人  uranusleon

枚举

What:枚举是什么

How:枚举是怎么实现的

enum Season {
    SPRING,
    SUMMER,
    AUTUMN,
    WINTER;
}
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Season.java
final class Season extends Enum
{

    public static Season[] values()
    {
        return (Season[])$VALUES.clone();
    }

    public static Season valueOf(String name)
    {
        return (Season)Enum.valueOf(EnumTest/Season, name);
    }

    private Season(String s, int i)
    {
        super(s, i);
    }

    public static final Season SPRING;
    public static final Season SUMMER;
    public static final Season AUTUMN;
    public static final Season WINTER;
    private static final Season $VALUES[];

    static 
    {
        SPRING = new Season("SPRING", 0);
        SUMMER = new Season("SUMMER", 1);
        AUTUMN = new Season("AUTUMN", 2);
        WINTER = new Season("WINTER", 3);
        $VALUES = (new Season[] {
            SPRING, SUMMER, AUTUMN, WINTER
        });
    }
}

枚举的线程安全

Enum

When and Where:枚举在什么时候可以使用

枚举和单例

上一篇下一篇

猜你喜欢

热点阅读