Hiya.
i would like to do dynamic casting for a java variable, the casting type is stored in a different variable.
this is regular casting:
String a = (String) 5;
this is what i want:
String theType = 'String';
String a = (theType) 5;
is it possible? and if so how? thanks!
update
I'm trying to populate a class with a hashMap that i received.
this is the constructor:
public ConnectParams(HashMap<String,Object> obj) {
for (Map.Entry<String, Object> entry : obj.entrySet()) {
try {
Field f = this.getClass().getField(entry.getKey());
f.set(this, entry.getValue()); /* <= CASTING PROBLEM */
} catch (NoSuchFieldException ex) {
log.error("did not find field '" + entry.getKey() + '"');
} catch (IllegalAccessException ex) {
log.error(ex.getMessage());
}
}
}
the problem here is that some of the classes variables are Double type, and if the number 3 is received it sees it as Integer and i have type problem.