0

I am creating an ENUM for some personal side project, and I wanted it to return the String value of each value if I desire to store the value as String variable in my code somewhere else.

for example:


public enum Month {

JANUARY, FEBRUARY, MARCH, APRIL,
MAY, JUNE, JULY, AUGUST,
SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER,

ID {
    public String id(Month month) {
        return month.toString();
    }
},

VALUE {
    public String value(Month month) {
        return month.toString();
    }
},

}


I would like to add id(); value() methods in my ENUM (let's say this is the one)

and when I chained either ID, or VALUE, I would like to get the String values; currently, it returns Month type.

I was trying if this works, but the return type of both ID and VALUE were still Month type.

Thanks in advance!!

(If possible reply in a way, so that I can promote your answer as part of thank you)

Luis Gouveia
  • 8,334
  • 9
  • 46
  • 68
Omutwar
  • 21
  • 2

0 Answers0