how to create the static enum like below
static enum Test{
employee-id,
employeeCode
}
As of now, I am getting errors.
This is not possible with Java, because each item has to be a valid identifier (and valid Java identifiers may not contain dashes).
The closest thing would be adding a custom property to each enum value or override the toString
method, so you can do the following:
Test.EMPLOYEE_ID.getRealName(); // Returns "employee-id"
Test.EMPLOYEE_CODE.getRealName(); // Returns "employeeCode"
public enum Test
EMPLOYEE_ID("employee-id"),
EMPLOYEE_CODE("employeeCode");
private Test(String realName) {
this.realName = realName;
}
public String getRealName() {
return realName;
}
private final String realName;
}
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