PageRenderTime 39ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/Jasyl.practice/src/main/java/designMode/proxy/dynamicProxy/DynamicSubject.java

https://gitlab.com/JasonZheng150214/Jasyl
Java | 45 lines | 24 code | 18 blank | 3 comment | 0 complexity | fd65ef440258c4d74f9711181e50c5d8 MD5 | raw file
  1. package designMode.proxy.dynamicProxy;
  2. import com.alibaba.fastjson.JSON;
  3. import java.lang.reflect.InvocationHandler;
  4. import java.lang.reflect.Method;
  5. /**
  6. * Created by jason on 16/6/3.
  7. */
  8. public class DynamicSubject implements InvocationHandler {
  9. private Object object;
  10. DynamicSubject(Object object){
  11. this.object = object;
  12. }
  13. @Override
  14. public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
  15. before();
  16. Object result = method.invoke(object, args);
  17. System.out.println(JSON.toJSON(result));
  18. after();
  19. return result;
  20. }
  21. public void before(){
  22. System.out.println("dynamic before");
  23. }
  24. public void after(){
  25. System.out.println("dynamic after");
  26. }
  27. }