mardi 13 octobre 2015

Retrieving instance of a class from class name

I am creating a program which uses reflection to register some annotated interface and stores the class names for latter use. I can retrieve the annotated classes pretty easily but know my question is: assuming that each of these interfaces is instantiated as a singleton, would be possible to retrieve the actual instance of the class from the class name? Please notice that I already know how to instantiate a new oject. But can I get one that already exists? I've googled it for a while and I've only found the Class.forName() method which I think is not what I am looking for (may be wrong though). In my project I'm also using Spring, so I'm also open to Spring solutions. Any help is really appreciated.

Thank you!





Aucun commentaire:

Enregistrer un commentaire