From 2992b5313bc4eef0fe1b5838620456f9df927eae Mon Sep 17 00:00:00 2001 From: chiba Date: Thu, 4 Sep 2003 06:49:28 +0000 Subject: made ClassPool.SimpleLoader public. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@42 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- tutorial/tutorial.html | 91 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 15 deletions(-) (limited to 'tutorial') diff --git a/tutorial/tutorial.html b/tutorial/tutorial.html index d0a26e3b..77c3dc97 100644 --- a/tutorial/tutorial.html +++ b/tutorial/tutorial.html @@ -115,7 +115,7 @@ to obtain the byte array written in a class file.

The default ClassPool returned by a static method ClassPool.getDefault() -searches the same path as the underlying JVM. +searches the same path as the underlying JVM (Java virtual machine). The users can expand this class search path if needed. For example, the following code adds a directory /usr/local/javalib @@ -336,6 +336,26 @@ by a single class loader. You should avoid loading part of the application program with the default class loader and the rest of the program with a user-defined class loader. +

In Java, multiple class loaders can coexist in Java and they form a +tree structure. Each class loader except the bootstrap loader has a +parent class loader, which normally loaded the class of that child +class loader. Since the request to load a class can be delegated along this +hierarchy of class loaders, a class may be loaded by a class loader that +you do not request the class loading. + +Furthermore, if a class loader CL requested to load a class C delegates +to the parenet class loader, then the class loader CL is never requested +to load any classes included in the definition of the class C. +Instead, the parent class loader of CL is requested to load them. + +

Different class loaders can load different class files with the +same class name. The loaded two classes are regarded as different +ones. If the same class file is loaded by two distinct class loaders, +the JVM makes two distinct classes with the same name and definition. +Since the two classes are not identical, an instance of one class is +not assignable to a variable of the other class. The cast operation +between the two classes fails and throws a ClassCastException. +


4.1 Using javassist.Loader

@@ -369,7 +389,7 @@ public class Main {

This program modifies a class test.Rectangle. The superclass of test.Rectangle is set to a test.Point class. Then this program loads the modified -class into the JVM, and creates a new instance of the +class, and creates a new instance of the test.Rectangle class.

The users can use a javassist.Translator object @@ -409,8 +429,8 @@ are loaded by different loaders. The application classes are loaded by javassist.Loader whereas the loader classes such as Main are by the default Java class loader. -

In Java, for security reasons, a single class file may be loaded -into the JVM by two distinct class loaders so that two different +

In Java, for security reasons, the same class file may be loaded +by two distinct class loaders so that two different classes would be created. For example,