Class Evolution

This is a demonstration of the class evolution mechanism implemented with Javassist. This mechanism enables a Java program to reload an existing class file. Although the reloaded class file is not applied to exiting objects (the old class file is used for those objects), it is effective in newly created objects.

Since the reloading is transparently executed, no programming convention is needed. However, there are some limitations on possible changes of the class definition. For example, the new class definition must have the same set of methods as the old one. These limitations are necessary for keeping the type system consistent.

Run WebPage.show()

The web server creates a new WebPage object and calls show() on that object. This method works as if it is a CGI script or a servlet and you will see the html file produced by this method on your browser.

Change WebPage.class

The web server overwrites class file WebPage.class on the local disk. Then it signals that WebPage.class must be reloaded into the JVM. If you run WebPage.show() again, you will see a different page on your browser.

Source files

Web server: DemoServer.java

WebPage: WebPage.java and another WebPage.java

Class loader: DemoLoader.java, Evolution.java, and VersionManager.java.