All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.huanminabc.utils_common.obj.proxy.jdk.ProxyJdkInstance Maven / Gradle / Ivy

There is a newer version: 1.0.5-RELEASE
Show newest version
package com.gitee.huanminabc.utils_common.obj.proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class ProxyJdkInstance {

    public static  T getObject(Class interfaceType,InvocationHandler invocationHandler) {
        return(T) Proxy.newProxyInstance(interfaceType.getClassLoader(),  new Class[] {interfaceType} ,invocationHandler);
    }
    public static  T getObject(Object o,InvocationHandler invocationHandler) {
        ClassLoader classLoader = o.getClass().getClassLoader();//类加载器。
        Class[] interfaces = o.getClass().getInterfaces();//对象所有接口
        return (T) Proxy.newProxyInstance(classLoader, interfaces ,invocationHandler);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy