SubjectDynamicProxy.java
上传用户:hensond
上传日期:2021-12-27
资源大小:817k
文件大小:1k
- package com.company.section2;
- import java.lang.reflect.InvocationHandler;
- /**
- * @author cbf4Life cbf4life@126.com
- * I'm glad to share my knowledge with you all.
- */
- public class SubjectDynamicProxy extends DynamicProxy{
- public static <T> T newProxyInstance(Subject subject){
- //获得ClassLoader
- ClassLoader loader = subject.getClass().getClassLoader();
- //获得接口数组
- Class<?>[] classes = subject.getClass().getInterfaces();
- //获得handler
- InvocationHandler handler = new MyInvocationHandler(subject);
- return newProxyInstance(loader, classes, handler);
- }
- }