0
I have a value that stores the status of an element. For example: 1 - sending 2 - Cancelled 3 - Error.
The value that will be saved in the database is the numeric value. I have a method that sets the status, but its parameter is of the numeric type.
The fact is that I didn’t want to have to pass the value on itself, but I wanted to pass using enum
.
setStatus (Status.CANCELADA);
public enum Status {
A_ENVIAR(1L), CANCELADA(2L), ERRO(3L);
private Long numVal;
Status(Long numVal) {
this.numVal = numVal;
}
public Long getNumVal() {
return numVal;
}
}
But to take the numerical value that each enum
represent, I’m having to do Status.CANCELADA.getNumVal()
.
Is there any way I can get the value "2" without calling the method getNumVal()
? I want the value 2 calling only Status.CANCELADA
.
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).
– Maniero