0
I am trying in various ways to get the value of an ENUM, but it just returns its "key". Below follows the ENUM:
public enum SaleType {
BOUGHT("Comprou"),
SEND_BUDGET("Enviar Orçamento"),
SUBMITTED_BUDGET("Orçamento Enviado"),
NOT_WANTED("Não quis"),
MAYBE_FUTURE("Pode Querer no Futuro");
private final String sale ;
private SaleType(String sale){
this.sale=sale;
}
public String getSaleType(){
return sale;
}
}
For example, I want to get the "content" of SEND_BUDGET, then made a loop in which will take all the values of my ENUM and make an IF to compare if the value matches...
for (SaleType s : SaleType.values()) {
if (si.getSaleType().equals(s)) {
String name = si.getSaleType();
SaleType valueOf = s.valueOf(SaleType.class, name);
System.out.println(valueOf);
}
}
But the problem is that it will always return me the key Ex:. SEND_BUDGET and not its corresponding value "Send Budget".
It is probably a basic doubt, but I have tried some forms and without success
By chance
si
is the typeSaleType
? If so, enums are one of the few cases where it is safe to compare with==
(i.e. change your ownif
forsi == s
).– mgibsonbr
Yes @mgibsonbr my si is of the type Saletype. Interesting! I will put in practice.
– João Manolo