I have the following class:
Topic.java
public enum Topic {
CONFIG3("config3"),
CONFIG2("config2"),
CONFIG1("config1")
;
private String name = null;
Topic(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
When I'm trying to do something like this:
switch (topicName) {
case Topic.CONFIG2.getName():
// Do my stuff
break;
}
The compiler shows an error: "Constant Expression required"
.
Since the Topic class is already used by many users, I wonder if there is any way to keep it in the same structure but also get the topic value as a constant (in this case - config2).
Any idea?