Answer the question
In order to leave comments, you need to log in
How to set the value of a variable with a dynamic name in java?
there is this code:
double var1;
String var2;
String var3
public bool setValue(String key, String value) {
/* ??? */
}
Answer the question
In order to leave comments, you need to log in
look at Reflection.
public bool setValue(String key, String value) {
try {
declaredField = this.getClass().getDeclaredField("var");
declaredField.set(this,value);
} catch (NoSuchFieldException e) {
return false
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question