My object:
public class Account(){
private String accountName;
private AccountType accountType; // enum
//I customized the getter by doing this...
public String getAccountType(){
return accountType.getAccountType();
}
}
My AccountType Enum:
public enum AccountType{
OLD("Old account"),
NEW("New account");
private final String accountType;
private AccountType(String accountType){
this.accountType = accountType;
}
public String getAccountType(){
return accountType;
}
}
I use ${account.accountType} to retrieve the value of the enum constant. Is this the correct way to do it?
I tried using AccountType.valueOf("OLD") but it returned OLD.
What’s the best practice for things like these?
Change your enum class like this;
and your Account object like this;
Then you can access
accountType.type