views:

87

answers:

1

Hi Java gurus,

I got a question: Is it possible to get a list of currently instantiated objects from the VM?

I am using a framework and try to implement an event handler (Hibernate, Interceptor). My problem now is that I need a Properties file during the execution of this handler. I cannot pass a reference to the Interceptor class, because Hibernate or the interface does not have such a method.

I now thought, why not trying to get the reference another way? Or is it possible to register global available objects during the runtime of an application?

Thanks for advice and regards from Germany,

Marco

+2  A: 

I now thought, why not trying to get the reference another way? Or is it possible to register global available objects during the runtime of an application?

You can use a public static field. This belongs to the class rather than to any instance of the class. Very simple example:

public class Properties {
    public static String PROPERTY = "abc";
}

You will then be able to access it from anywhere with:

Properties.PROPERTY

You can find more here:

http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html

Bruno Rothgiesser
Of course :) I mixed up static and final! Thanks a lot! The link is a pretty good read :)
Marco Nätlitz
You're welcome. Note that in my example maybe I shouldn't have chosen an upper case name for the field, since it is not supposed to be constant.
Bruno Rothgiesser