aboutsummaryrefslogtreecommitdiffstats
path: root/sample/reflect/Person.java
diff options
context:
space:
mode:
Diffstat (limited to 'sample/reflect/Person.java')
-rw-r--r--sample/reflect/Person.java54
1 files changed, 28 insertions, 26 deletions
diff --git a/sample/reflect/Person.java b/sample/reflect/Person.java
index 5e0e2ad8..445d3807 100644
--- a/sample/reflect/Person.java
+++ b/sample/reflect/Person.java
@@ -1,6 +1,6 @@
/*
- A base-level class controlled by VerboseMetaobj.
-*/
+ * A base-level class controlled by VerboseMetaobj.
+ */
package sample.reflect;
@@ -9,43 +9,45 @@ import javassist.reflect.Metaobject;
public class Person {
public String name;
+
public static int birth = 3;
+
public static final String defaultName = "John";
public Person(String name, int birthYear) {
- if (name == null)
- this.name = defaultName;
- else
- this.name = name;
+ if (name == null)
+ this.name = defaultName;
+ else
+ this.name = name;
- this.birth = birthYear;
+ birth = birthYear;
}
public String getName() {
- return name;
+ return name;
}
public int getAge(int year) {
- return year - birth;
+ return year - birth;
}
public static void main(String[] args) {
- String name;
- if (args.length > 0)
- name = args[0];
- else
- name = "Bill";
-
- Person p = new Person(name, 1960);
- System.out.println("name: " + p.getName());
- System.out.println("object: " + p.toString());
-
- // change the metaobject of p.
- if (p instanceof Metalevel) {
- ((Metalevel)p)._setMetaobject(new Metaobject(p, null));
- System.out.println("<< the metaobject was changed.>>");
- }
-
- System.out.println("age: " + p.getAge(1999));
+ String name;
+ if (args.length > 0)
+ name = args[0];
+ else
+ name = "Bill";
+
+ Person p = new Person(name, 1960);
+ System.out.println("name: " + p.getName());
+ System.out.println("object: " + p.toString());
+
+ // change the metaobject of p.
+ if (p instanceof Metalevel) {
+ ((Metalevel)p)._setMetaobject(new Metaobject(p, null));
+ System.out.println("<< the metaobject was changed.>>");
+ }
+
+ System.out.println("age: " + p.getAge(1999));
}
}