accessing a variable from "ex"+ i
i’m trying to do something which i normally do in flash actionscript very easily but didn’t manage to find out how to do it in java, it is easier to show an example:
private int ex1=1;
private int ex2=2;
private int ex3=3;
private int ex4=4;
private int ex5=5;
my goal is that in the end my VALS array should be like this:
instead i get this:
how can i make java to interpret the "ex"+i and read the variable "ex1", "ex2"…
thankx in advance
You can’t accomplish this in the way you’re approaching, due to the
very different in this way from Java/C/C++, using dynamic binding at
runtime. So you’ll need to find a different solution (e.g. use an
array for your ex variables, store values in a hashtable which is
dynamically resolved at runtime, manually type all the code rather
than using a for loop, or some other approach).
On 27 Mar 2006, at 21:17, Joshua Kit Clayton wrote:
> You can’t accomplish this in the way you’re approaching, due to the
> static nature of Java compilation.
Actually, it could probably be achieved using the reflection API, but
it would be untidy and not very efficient. From the fragment of the
example given, it’s not clear to me why it’s necessary to do the
coding this way.
nick rothwell — composition, systems, performance — http://
thankx for the enlightment, at least now i now that it’s not possible. i allways find out a way to go around this but sometimes i just wish it could be possible.
the example i gave was not a real example, it was just to be simpler for you to help me, so it was easy to go around it…