First off, sorry for my english...
I'm doing a Enum type but I can't do, because I'm using tipo(String nombre, short valor)
Why must I use tipo(String nombre, int valor)? Using int instead of short?
public enum Tipo {
// The constructor (String, int) is undefined
DAT ("DAT", -2);
private String nombre;
private short valor;
tipo(String nombre, short valor){
this.nombre = nombre;
this.valor = valor;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public short getValor() {
return valor;
}
public void setValor(short valor) {
this.valor = valor;
}
}
Try DAT ("DAT", (short)-2);
You are passing an int to a constructor that takes a short. Java doesn't auto-cast from int to short because of the potential loss of data.
A very good explanation of this can be found here - primitive type short casting in java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With