Java的编译器给enum自动添加了哪些专用方法?

from Java Tutorial:

Java programming language enum types are much more powerful than their counterparts in other languages. The enum declaration defines a class (called an enum type). The enum class body can include methods and other fields. The compiler automatically adds some special methods when it creates an enum. For example, they have a static values method that returns an array containing all of the values of the enum in the order they are declared. This method is commonly used in combination with the for-each construct to iterate over the values of an enum type. For example, this code from the Planet class example below iterates over all the planets in the solar system.

请问:
除values()方法外,编译器还给这个enum添加了哪些方法?
简单例子 :
enum Test{
    Spring,Summer,Autumn,Winter
}
反编译的结果:
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: [url]http://www.kpdus.com/jad.html[/url]
// Decompiler options: packimports(3)
// Source File Name:   Test.java


final class Test extends Enum
{

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

    public static Test valueOf(String s)
    {
        return (Test)Enum.valueOf(Test, s);
    }

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

    public static final Test Spring;
    public static final Test Summer;
    public static final Test Autumn;
    public static final Test Winter;
    private static final Test $VALUES[];

    static
    {
        Spring = new Test("Spring", 0);
        Summer = new Test("Summer", 1);
        Autumn = new Test("Autumn", 2);
        Winter = new Test("Winter", 3);
        $VALUES = (new Test[] {
            Spring, Summer, Autumn, Winter
        });
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值