metadata - "Metaaccess" of Objects in Java With Variables in the Identifiers -


i want access number of objects in java without write lot of code, example:

int x;   for(x=0;x<5;x++){     jlabelx = /*do something*/ } 

would this:

when x=0 jlabel0 access, x=1 jlabel1 , on...

is there way of doing this? or need specify cases

the best way of doing not have variables called jlabel0, jlabel1 etc in first place. instead, have array variable (or other collection):

jlabel[] labels = new jlabel[5];  (int = 0; < labels.length; i++) {     labels[i] = new jlabel();     // whatever 

you can @ fields reflection, time see variables x0, x1, x2 etc shudder - it's clear indication collection of kind better fit.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -