Reflection

Hi

I am working on a small program using reflection to print out information about classes. A very simple program but I have a problem that I dont know how to solve. I hope someone can help me out. The problem occurs when I first specifie the classname for the class the program will display the information. This works fine but I would like to be able to change the class and compile it in a seperate window while my class information program is still running. After the compile is done I would like the program to look after the "new class", ie but is has the same name. Unfortunate it seams that the old version of the class is stuck in memory and I cant find a way to load the new version. Is this possible?

Any help is more than welcomed.

Markus Backman

[790 byte] By [backmask] at [2007-9-26 14:04:08]
# 1

A class is uniquely identified by two things, its class loader and its name. A class is not unloaded (gc'd) unless its class loader is. The system class loader is never gc'd. So a class loaded by the system class loader will never be unloaded.

If you want to dynamically load new versions of a class you need to create your own class loader and use it to load the new version. When a new version of the class is needed then a new class loader will be needed to.

You can find discussions of this in the Advance Programming forum. Search for class loader and URLClassLoader.

jschell at 2007-7-2 15:20:08 > top of Java-index,Java HotSpot Virtual Machine,Specifications...