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?
Answer
Try this out. I have created a method which searches type using id:
public static Type getType(int id) {
for (Type type : Type.values()) {
if (id == type.getId()) {
return type;
}
}
return null;
}
No comments:
Post a Comment