Proxy错题集

Mapper instance =(Mapper) MyProxy.Getproxy(Mapper.class);

public static Object Getproxy(Class<?> bigClass) {

System.out.println(bigClass);

控制台打印: interface com.tedu.Mapper 对象是接口

---------------------------------------------------------------------------正确

Mapper mapper= new UserMapper();
Mapper instance =(Mapper) MyProxy.Getproxy(user.getClass());

Class<?>[] interfaces = bigClass.getInterfaces();
System.out.println(interfaces);

------------------------------------------------------------------------------正确

Mapper instance =(Mapper) MyProxy.Getproxy(Mapper.class);

public static Object Getproxy(Class<?> bigClass) {}

Class<?>[] interfaces = bigClass.getInterfaces();
System.out.println(interfaces);

控制台输出:[Ljava.lang.Class;@659e0bfd,这里你将接口变成了UserMapperClass类了.

=============================================

终结.Mapper.class 是接口 ,user.getClass();是UserMapperClass对象.

 

public class 动态代理参数 {
    Proxy.newProxyInstance(
              NullRobot.class.getClassLoader(),//这里为什么用这个类加载器啊?
              new Class[]{ Null.class, Robot.class },
              new NullRobotProxyHandler(type));
}

第2个参数,用userMapper.getclass.getInterfaces(),   或   new Class[]{ Null.class, Robot.class },

一定不能用Mapper.class

atzhang

posted @ 2020-05-11 23:04  张艳涛&java  阅读(116)  评论(0编辑  收藏  举报