I have created an enum as so:
enum Types { hi, hello, bye }
I have added a getter inside each individual enum as so:
enum Types {
hi {
String test = "From hi";
public String getString() {
return test;
},
etc.
}
Except I cannot call “Types.hi.getString()”. Is there any way to do this? Thanks!
In your enum class, define the method you want to access as
public abstract.Like so:
As an alternative, let your enum class implement an interface: