I have the following enum :
public enum Rank{
FIRST,
SECOND
}
Whenever a toString() function is called on an enum (or its used inside a string literal), I want FIRST_RANK returned (instead of the string ‘FIRST‘, as is default). If I override the toString() function like :
@Override
public String toString(){
return this.toString() + "_RANK";
}
But this would obviously lead to recursion. The problem is that I need to use the default toString() implementation of enums, and there is no superclass of enums whose toString() I can call.
Whenever you want the name of that enum instance, you should use the
name()method. In your example: