File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
java-Javassist/src/com/zyj/javassist Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change
1
+ package com .zyj .javassist ;
2
+
3
+ public @interface Author {
4
+ String name ();
5
+ int year ();
6
+
7
+ }
Original file line number Diff line number Diff line change @@ -116,7 +116,33 @@ public static void test04()throws Exception{
116
116
Object re = getter .invoke (obj );
117
117
System .out .println ("salary:::" +re );
118
118
}
119
+
120
+ /**
121
+ * 操作注解
122
+ * @throws Exception
123
+ */
124
+ public static void test06 () throws Exception {
125
+ CtClass cc = ClassPool .getDefault ().get ("com.zyj.javassist.Emp" );
126
+ Object annotation = cc .getAnnotation (Author .class );
127
+ Author author = (Author ) annotation ;
128
+ System .out .println ("name:" +author .name ()+",year:" +author .year ());
129
+ }
130
+
131
+ /**
132
+ * g构造器
133
+ * @throws Exception
134
+ */
135
+ public static void test05 ()throws Exception {
136
+ ClassPool pool = ClassPool .getDefault ();
137
+ CtClass cc = pool .get ("com.zyj.javassist.Emp" );
138
+ CtConstructor [] cs = cc .getConstructors ();
139
+ for (CtConstructor c :cs ){
140
+ System .out .println (c .getLongName ());
141
+ //c.insertBeforeBody();
142
+ }
143
+
144
+ }
119
145
public static void main (String [] args ) throws Exception {
120
- test04 ();
146
+ test06 ();
121
147
}
122
148
}
Original file line number Diff line number Diff line change 8
8
* @Version : v1.0
9
9
* @description
10
10
**/
11
+ @ Author (name ="zyj" ,year = 2018 )
11
12
public class Emp {
12
13
private String empno ;
13
14
private String ename ;
You can’t perform that action at this time.
0 commit comments