Is there a simple way of obtaining all object instances of a specific class in Java

后端 未结 6 1513
终归单人心
终归单人心 2020-11-29 09:12

Currently I am working on a Java agent to assemble memory stats. With the help of the instrumentation API I can get a hold of the classes (and manipulate them). With plain J

6条回答
  •  余生分开走
    2020-11-29 10:06

    From what I've been told in previous posts, there is no way to get a list of all the instances of a class in Java. The reflection API does some neat things but not this specific thing.

    The best thing you can do is hold pointers to all objects but that seems obscene and doesn't work on other people's programs. Not ideal eh?

提交回复
热议问题