I want to have a Java enum whose values are integers.
For example:
public enum TaskStatus {
TaskCreated(1),
TaskDeleted(2)
}
A minimalistic answer. If the ordinal value suffices, you can do without.
public enum TaskStatus {
None,
TaskCreated,
TaskDeleted;
@Override
public String toString() {
// Replace upper-case with a space in front, remove the first space.
return super.toString()
.replaceAll("\\p{U}", " $0")
.replaceFirst("^ ", "");
}
}