You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Main.java 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. package sample.reflect;
  2. import javassist.tools.reflect.Loader;
  3. /*
  4. The "verbose metaobject" example (JDK 1.2 or later only).
  5. Since this program registers class Person as a reflective class
  6. (in a more realistic demonstration, what classes are reflective
  7. would be specified by some configuration file), the class loader
  8. modifies Person.class when loading into the JVM so that the class
  9. Person is changed into a reflective class and a Person object is
  10. controlled by a VerboseMetaobj.
  11. To run,
  12. % java javassist.tools.reflect.Loader sample.reflect.Main Joe
  13. Compare this result with that of the regular execution without reflection:
  14. % java sample.reflect.Person Joe
  15. */
  16. public class Main {
  17. public static void main(String[] args) throws Throwable {
  18. Loader cl = (Loader)Main.class.getClassLoader();
  19. cl.makeReflective("sample.reflect.Person",
  20. "sample.reflect.VerboseMetaobj",
  21. "javassist.tools.reflect.ClassMetaobject");
  22. cl.run("sample.reflect.Person", args);
  23. }
  24. }