java 5.0 enum.

java core 2005. 5. 12. 19:04

java 의 enum은 컴파일러가 지원하는 primitive 타입이 아니라 컴파일러가 클래스로 변환시킨다.
Enum 클래스를 상속받은 static final class로서, 내부 요소들은 해당 클래스의 인스턴스를 가진다.

public class EnumType {
    public enum Editor {A1, A2};
    public static void main(String[] args) {
        System.out.println(Editor.A1);
    }
}

jad로 변환시키니, 다음과 같이 나왔다.


// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst nonlb space
// Source File Name:   EnumType.java

import java.io.PrintStream;

public class EnumType {
    public static final class Editor extends Enum {

        public static final Editor A1;
        public static final Editor A2;
        private static final Editor $VALUES[];

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

        public static Editor valueOf(String s) {
            return (Editor)Enum.valueOf(EnumType$Editor, s);
        }

        static  {
            A1 = new Editor("A1", 0);
            A2 = new Editor("A2", 1);
            $VALUES = (new Editor[] {
                A1, A2
            });
        }

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


    public EnumType() {
    }

    public static void main(String args[]) {
        System.out.println(Editor.A1);
    }
}

'java core' 카테고리의 다른 글

Runtime  (0) 2005.06.06
millisecond를 가지고 구하기  (0) 2005.05.13
jdk 5.0 static import test code  (0) 2005.05.11
jdk 5.0 Annotation, Enum Test code  (0) 2005.05.11
jdk 5.0 Annotation Test Code  (0) 2005.05.11
Posted by '김용환'
,