File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get all instances of a class

 
Bat Haar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
anyone knows how to get all instances of a class;
something like ArrayList.getInstances() and I get all the instances of class ArrayList.
Thanx
Bat
 
Mikael Jonasson
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default there isn't a way (I think). But you could always write a static method that does this for your own classes.
/Mike
 
Bat Haar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Mikael,
but how should this static method work?
Bat
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one way of doing this...

 
William Barnes
Ranch Hand
Posts: 986
Eclipse IDE Firefox Browser Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "finalize" do that isn't done by the gc when the class gets cleaned up? Thanks.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, finalize is run by the garbage collector whenever an object has no more active references... actually, that brings up a good question... I added the finalize() in so that the reference in the hashmap would be removed, but I think the very fact that the object exists in the hashmap means that finalize will never be run because the hashmap will always contain an active reference... I guess I didn't think it through that well... So either all objects of this class never get garbage collected until the program is over, or you have to add a special method to remove the reference from the hashmap to get rid of all active references...

-Nate
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic