/Jasyl.practice/src/main/java/designMode/proxy/dynamicProxy/DynamicSubject.java
Java | 45 lines | 24 code | 18 blank | 3 comment | 0 complexity | fd65ef440258c4d74f9711181e50c5d8 MD5 | raw file
- package designMode.proxy.dynamicProxy;
- import com.alibaba.fastjson.JSON;
- import java.lang.reflect.InvocationHandler;
- import java.lang.reflect.Method;
- /**
- * Created by jason on 16/6/3.
- */
- public class DynamicSubject implements InvocationHandler {
- private Object object;
- DynamicSubject(Object object){
- this.object = object;
- }
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- before();
- Object result = method.invoke(object, args);
- System.out.println(JSON.toJSON(result));
- after();
- return result;
- }
- public void before(){
- System.out.println("dynamic before");
- }
- public void after(){
- System.out.println("dynamic after");
- }
- }