creat an enumeration that containt Integer variables

Viewed 46

I want to create an enumeration that containt Integer variables , the result is needed to be something like this :

@AllArgsConstructor
@Getter
public enum Test {

    1("Test1"),
    2("Test2");
    private final String value;
}
1 Answers

As far as I know there is no such thing like this in Java.
If you really need enum for that, you can do it in reverse:

 public enum TestEnum {

    TEST_1(1),
    TEST_2(2);

    private final int value;

    TestEnum(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }
}
Related