android tech.
enum 활용
zimamdero
2016. 10. 6. 13:08
public enum TestEnum {
TEST_0(0, "text 0", 12),
TEST_1(1, "text 1", 34)),
TEST_2(2, "text 2", 56)
private final int value0;
private final String value1;
private final int value2;
TestEnum(int v0, String v1, int v2) {
value0 = v0;
value1 = v1;
value2 = v2;
}
public int getValue0( ) {
return value0;
}
public String getValue1( ) {
return value1
}
public int getValue2( ) {
return value2;
}
}
...
TestEnum test0 = TestEnum.TEST_0;
TestEnum test1 = TestEnum.TEST_1;
TestEnum test2 = TestEnum.TEST_2;
int num = test0.getValue0( );
String text = test0.getValue1( );
int count = test0.getValue2( );
클래스와 같이 사용이 가능.
컴파일 될 때, 변수들은 값이 정의 되어 져야 한다.
생성자는 private