Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuple Enum in Java

Tags:

java

I'm very new in Java and were wondering and didn't find anything about it.

Can you create enum tuple ?

public enum Status {OPEN : "1", CLOSED: "2", DELETED: "3"}

I will need to access both "OPEN" or "1"

like image 284
ArniReynir Avatar asked Dec 15 '22 21:12

ArniReynir


1 Answers

You could always create a custom constructor for your enum..

public enum Status {


    OPEN("1"),
    CLOSED("2"),
    DELETED("3");

    private String code;

    public Status(String code) {
        this.code = code;
    }

    public String getCode() {
        return code;
    }
}

Then you can access with Status.OPEN.getCode(). This functions as an effective mapping between an enum type and a code value.

like image 64
christopher Avatar answered Dec 22 '22 01:12

christopher