Skip to content

Instantly share code, notes, and snippets.

@hacke2
Created August 25, 2014 13:51
Show Gist options
  • Save hacke2/1000c34eef247ba8b175 to your computer and use it in GitHub Desktop.
Save hacke2/1000c34eef247ba8b175 to your computer and use it in GitHub Desktop.
动态代理及JDK动态代理源码分析
public class LogProxy implements InvocationHandler {
private Object object;
public LogProxy(Object object) {
super();
this.object = object;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
method.invoke(this.object, args);
System.out.println("记录到数据库..");
return null;
}
public void setObject(Object object) {
this.object = object;
}
public Object getObject() {
return object;
}
}
public class PowerProxy implements InvocationHandler {
private Object object;
public PowerProxy(Object object) {
super();
this.object = object;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
System.out.println("进行权限验证..是否是黑名单..");
method.invoke(this.object, args);
return null;
}
public void setObject(Object object) {
this.object = object;
}
public Object getObject() {
return object;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment