Instantiate class from string

I googled methods but couldn’t get it to work in processing.

what I’m looking for is something like.

String s="foo";

void setup(){

parent new_instance= new s;
}

class parent{

}

class foo extends parent{

}

Seems like what you might be looking for is reflections

2 Likes

Re: reflection on this forum:

@GoToLoop has spent quite a bit of time on reflection in Processing.


The Processing API uses a related technique, a string as a method name (rather than a class name) in, for example, selectFolder – internally it calls selectMethod, which uses .getMethod() to turn the text String callbackMethod argument given to selectFolder into the corresponding Processing function (Method selectMethod) for the callback.

1 Like