A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

[mw_shl_code=applescript,true]public static void main(String[] args) {
                UserImp ui = new UserImp();
                ui.add();
                ui.del();
               
                System.out.println("-----------------------");
                //通过反射生成的代理对象
                User user = (User) Proxy.newProxyInstance(ui.getClass().getClassLoader(),
                                ui.getClass().getInterfaces(), new MyInvocationHandler(ui)); //返回一个接口
                user.add();
                user.del();
                System.out.println("-------------------------");
               
                //学生登录
                StudentImp si = new StudentImp();
                si.login();
                si.submit();
                Student s = (Student) Proxy.newProxyInstance(si.getClass().getClassLoader(),  //返回一个接口
                                si.getClass().getInterfaces(), new MyInvocationHandler(si));
                s.login();
                s.submit();
        }[/mw_shl_code]

哪位大神知道Proxy静态方法newProxyInstance()方法返回值为什么是接口类型?查一下API文档,返回值是Object

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马