MyInterface intf = (MyInterface) Class.forName(className).newInstance();
I have a specific piece of code that will create new interfaces on demand using the above call and call a specific method. All implementation classes usually contain many variables final staticand static initialization code, which I would like to run only once in my life.
But since I use the call to newInstance (), I get the impression that the old object gets GCed, and the class is initialized again and, therefore, all static variables.
To avoid this, I would like to put this in the cache so that these classes are not built again and therefore would be initialized once during its lifetime. (Note: My interfaces are thread safe).
Should I just put this in Hashtableand just see it or is it better to process the cache?
source
share