Vorsicht beim "Enum-Pattern"!

Thomas Darimont

Erfahrenes Mitglied
Hallo!

Siehe:
http://www.javaworld.com/javaworld/javatips/jw-javatip122.html

Es wäre nun mal nett zu wissen, ob die Klassen die von den Java 5 enums generiert werden auch diesen "Umstand" berücksichtigen...
Code:
/*
 * Created on 21.12.2004
 */
package de.tutorials;

/**
 * @author Darimont
 *
 */
public enum MyEnum {
	ROT,GRUEN,BLAU;
}

Ergibt:

Code:
// Decompiled by DJ v3.6.6.79 Copyright 2004 Atanas Neshkov  Date: 21.12.2004 11:55:50
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MyEnum.java

package de.tutorials;


public class MyEnum extends Enum
{

    public MyEnum(String s, int i)
    {
        super(s, i);
    }

    public static final MyEnum[] values()
    {
        MyEnum amyenum[];
        int i;
        MyEnum amyenum1[];
        System.arraycopy(amyenum = ENUM$VALUES, 0, amyenum1 = new MyEnum[i = amyenum.length], 0, i);
        return amyenum1;
    }

    public static final MyEnum valueOf(String s)
    {
        MyEnum amyenum[];
        MyEnum myenum;
        for(int i = (amyenum = ENUM$VALUES).length; --i >= 0;)
            if(s.equals((myenum = amyenum[i]).name()))
                return myenum;

        throw new IllegalArgumentException(s);
    }

    public static final MyEnum ROT;
    public static final MyEnum GRUEN;
    public static final MyEnum BLAU;
    private static final MyEnum ENUM$VALUES[];

    static 
    {
        ROT = new MyEnum("ROT", 0);
        GRUEN = new MyEnum("GRUEN", 1);
        BLAU = new MyEnum("BLAU", 2);
        ENUM$VALUES = (new MyEnum[] {
            ROT, GRUEN, BLAU
        });
    }
}

...

Gruß Tom
 
Zurück