MyInterface intf = (MyInterface) Class.forName(className).newInstance();
I have a certain piece of code which will create new interfaces on demand using the above call and invoke a certain method. All of the implementation classes usually contain lots of final static
variables and static initialization code which I would like to fire only once in its lifetime.
But since I am using the newInstance() call, I am under the impression that the old object gets GCed and the class is initialized again and hence all the static variables.
In order to avoid this, I would like to put this in a cache, so that these classes are not re-constructed again and hence would be initialized once during its lifetime. (Note: My interfaces are thread-safe).
Should I just put this in a Hashtable
and just look it up or is there a better way to handle the cache?