FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   class reference represented by string ?!?!
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: class reference represented by string ?!?!  (Read 213 times)
camp_Safari


class reference represented by string ?!?!
« on: Nov 23rd, 2004, 2:58pm »

hi  
i have a couple of different subclasses that should be instanciated at runtime in a for loop, like this:
 
String [] items;
items = new String[3];
items[0] = "subclass1";
items[1] = "subclass2";
items[2] = "subclass3";
 
 
Superclass [] instances;
instances = new Superclass[3];
 
for (int i = 0; i < 2; i++){
    String subClass = items[i];
    instances[i] = new subClass ();
}
 
my problem is, how to tread the variable subClass as a reference to the class? so that a new instance is created from the class represented by the variable of type string?
 
thnx.
 
Pages: 1 

« Previous topic | Next topic »