my final goal is to be able to reload classes after they have been already loaded to the JVM.
After reading the following answer Unloading classes in java? , I have been trying to implement my own Class-Loader, which itself creates a different instance of Class-Loader(same type of it's own) for each class it loads.
so, the outcome is one class per one Class-Loader.
The purpose is to be able to GC the class, meaning all of its instances, then to unload its class-loader , and to be able to reload the same class from its bytes.
the problem is - I can see my class instance being garbage collected using finalize() method, but I cant get my Class-Loader to unload, or to be garbage collected .
is there any code example, a simple test, that shows how it can be done?
thanks, any help would be appreciated
Edit:
to be clearer , i am interested in code examples where the instantiation of the new objects is via the 'new( )' operand, and the Class-loader isn't explicitly reloading the Class in the main, but after the next 'new( )' is called.