aspose file tools*
The moose likes Java in General and the fly likes How to get all instances of a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get all instances of a class" Watch "How to get all instances of a class" New topic
Author

How to get all instances of a class

Bat Haar
Greenhorn

Joined: Aug 02, 2001
Posts: 2
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

Joined: May 16, 2001
Posts: 158
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

Joined: Aug 02, 2001
Posts: 2
Thanx Mikael,
but how should this static method work?
Bat
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Here's one way of doing this...



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 984

What does "finalize" do that isn't done by the gc when the class gets cleaned up? Thanks.


Please ignore post, I have no idea what I am talking about.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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
 
subject: How to get all instances of a class
 
Similar Threads
memory allocation
enforcing URL rewriting in Tomcat
Difference between Static and Instance variable
instances of an action class
Variable access