`

ex1) Enum 클래스

Enum Class 생성

public enum TestEnum {
    MOVE_IN ("code1", 1 , "Y"),
    MOVE_OUT("code2", 2 , "N")
    ;
    
    private String code;
    private int num;
    private String useYn;

    TestEnum(String code, int num, String useYn) {
        this.code = code;
        this.num = num;
        this.useYn = useYn;
    }

    public String getCode() {
        return code;
    }
    public int getNum() {
        return num;
    }
    public String getUseYn() {
        return useYn;
    }
}


Enum 사용

public class Test {
    public static void main(String...args) {
    
        String code = TestEnum.MOVE_OUT.getCode();
        int num = TestEnum.MOVE_IN.getNum();
        String useYn = TestEnum.MOVE_IN.getUseYn();

        System.out.println(code); //code2
        System.out.println(num); //1
        System.out.println(useYn); //Y
    }
}



ex2) Enum 메서드


Enum 메서드 생성


public class TestConst {    

public enum Gender {


MAN1 ( "홍길동", 010, 18 ),
MAN2 ( "슈퍼맨", 011, 22 ),
MAN3 ( "이이이", 444, 100)
;
private String name;
private int phone;
private int age;

Gender(String name, int phone, int age) {

    this.name = name;
    this.phone = phone;
    this.age = age;
}

public String getName() {
    return name;
}
public int getPhone() {
    return phone;
}
public int getAge() {
    return age;
}

}
   
public enum RfcName {
    ORDER("RFC_ORDER"),
    LIST("RFC_LIST"),
    MODIFY("RFC_MODIFY"),
    REMOVE("RFC_REMOVE")
    ;
    private String interfaceName;
    RfcName(String interfaceName) {
        this.interfaceName = interfaceName;
    }
    public String getInterfaceName() {
        return interfaceName;
    }

}

}


Enum 사용

public class Test {
    public static void main(String...args) {
       

String name = TestConst.Gender.MAN1.getName();
int phone = TestConst.Gender.MAN3.getPhone();
int age = TestConst.Gender.MAN2.getAge();
System.out.println(name); // 홍길동
System.out.println(phone); // 444
System.out.println(age); // 22

String ifName = TestConst.RfcName.ORDER.getInterfaceName();
String ifName2 = TestConst.RfcName.REMOVE.getInterfaceName();
System.out.println(ifName); // RFC_ORDER
System.out.println(ifName2);// RFC_REMOVE


}

}

`


+ Recent posts