diff options
Diffstat (limited to 'sample/reflect/Main.java')
-rw-r--r-- | sample/reflect/Main.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/sample/reflect/Main.java b/sample/reflect/Main.java new file mode 100644 index 00000000..6086d9f8 --- /dev/null +++ b/sample/reflect/Main.java @@ -0,0 +1,33 @@ +package sample.reflect;
+
+import javassist.reflect.ClassMetaobject;
+import javassist.reflect.Loader;
+
+/*
+ The "verbose metaobject" example (JDK 1.2 or later only).
+
+ Since this program registers class Person as a reflective class
+ (in a more realistic demonstration, what classes are reflective
+ would be specified by some configuration file), the class loader
+ modifies Person.class when loading into the JVM so that the class
+ Person is changed into a reflective class and a Person object is
+ controlled by a VerboseMetaobj.
+
+ To run,
+
+ % java javassist.reflect.Loader sample.reflect.Main Joe
+
+ Compare this result with that of the regular execution without reflection:
+
+ % java sample.reflect.Person Joe
+*/
+public class Main {
+ public static void main(String[] args) throws Throwable {
+ Loader cl = (Loader)Main.class.getClassLoader();
+ cl.makeReflective("sample.reflect.Person",
+ "sample.reflect.VerboseMetaobj",
+ "javassist.reflect.ClassMetaobject");
+
+ cl.run("sample.reflect.Person", args);
+ }
+}
|