I have an Enum:
public enum Type {
    ADMIN(1), 
    HIRER(2), 
    EMPLOYEE(3);
    private final int id;
    Type(int id){
        this.id = id;       
    }
    public int getId() {
        return id;
    }
}
How can I get a Type enum passing an id property?
You can build a map to do this lookup.
static final Map<Integer, Type> id2type = new HashMap<>();
static {
    for (Type t : values())
        id2type.put(t.id, t);
}
public static Type forId(int id) {
    return id2type.get(id);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With