I have this scenario...
public enum ParametrosAplicacion{
BOOLEAN("BOOLEANO", "Valor verdadero o falso", Boolean.class, false),
FILE("PROPIEDAD", "DESCRIPCION", File.class, new File("ruta"));
private final String propiedad, descripcion;
private final Class<?> clase;
private Object valor;
private ParametrosAplicacion(String p, String d, Class<?> c, Object v){
this.propiedad=p;
this.descripcion=d;
this.clase=c;
this.valor=v;
}
public Class<?> getClase(){
return this.clase;
}
public <V> V getValor(Class<V> clase){
return clase.cast(valor);
}
public static void main(String[] args){
Boolean sw=ParametrosAplicacion.BOOLEAN.getValor(Boolean.class);
if(sw){
System.out.println(sw.getClass().getSimpleName());
}else{
File file=ParametrosAplicacion.FILE.getValor(File.class);
System.out.println(file.getClass().getSimpleName());
}
}
}
I am finding for some way to get values a this way...
Boolean sw=ParametrosAplicacion.BOOLEAN.getValor();
Some thing like...
public <V> V getValor(){
return this.clase.cast(this.valor); // not compile!!!
}
Of course I need to skip any unchecked warning, so....
public <V> V getValor(){
return (V)(valor);
}
Is not a good solution...
Thanks a lot...