Read objects from a .class file

I'm trying to use Javassist in order to get all the instantiated objects in a .class file, however, I can't seem to find the way to do so, so I ask, is there any way to get, for example, an array of Objects from a .class file?

Here is the class from which I would like to get the instantiated objects:

public class Test {

    public static void main(String[] args){

        System.out.println(new Widget());
        System.out.println(new Widget("width", 80));
        System.out.println(new Widget("height", 30));
        System.out.println(new Widget("height", 20, "width", 90));

    }

}

Widget's constructor is simply

public Widget(Object ...args) {}

Thanks!

Upvotes: 0

Views: 77

Answers (1)

Alexei Kaigorodov
Alexei Kaigorodov

Reputation: 13535

.class file does not contain instantiated objects. They are created at runtime, when the method main() is called.

For the given example, there is no way to collect instantiated objects even at runtime.

Upvotes: 1

Related Questions