Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
35 lines (32 loc) · 924 Bytes

File metadata and controls

35 lines (32 loc) · 924 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import proxy.imp.AOPMethod;
public class AOPHandle implements InvocationHandler{
//保存对象
private AOPMethod method;
private Object o;
public AOPHandle(Object o,AOPMethod method) {
this.o=o;
this.method=method;
}
/**
* 这个方法会自动调用,Java动态代理机制
* 会传入下面是个参数
* @param Object proxy 代理对象的接口,不同于对象
* @param Method method 被调用方法
* @param Object[] args 方法参数
* 不能使用invoke时使用proxy作为反射参数时,因为代理对象的接口,不同于对象
* 这种代理机制是面向接口,而不是面向类的
**/
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object ret=null;
//修改的地方在这里哦
this.method.before(proxy, method, args);
ret=method.invoke(o, args);
//修改的地方在这里哦
this.method.after(proxy, method, args);
return ret;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.