Java Reflection: get instances of a given class found by entering its name?

Tom picture Tom · Feb 21, 2011 · Viewed 13.1k times · Source

Is it possible to get all instances of a class by entering this class's name as a string?

Something like this?

var instances = Reflection.findClass("com.someone.MyClass").getInstances();

Any feedback is appreciated. Thanks.

Answer

Jon Skeet picture Jon Skeet · Feb 21, 2011

No, there's nothing like that available. If you hook into the debugging API you may be able to do it, but not when running "normally".