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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 苏伯亚 中级黑马   /  2014-4-1 16:15  /  820 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

这是代码
public static void main(String[] args) throws Exception {
                // TODO Auto-generated method stub

                Method applyMethod = GenericTest.class.getMethod("applyVector", Vector.class);
                Type [] types=applyMethod.getGenericParameterTypes();
                ParameterizedType pType=(ParameterizedType)types[0];
                System.out.println(pType.getRawType());
        }
       
        private static void applyVector(Vector<Date>v1){
               
        }

总是报这个错误 我异常处理了啊
Exception in thread "main" java.lang.NoSuchMethodException: cn.itcast.day2.GenericTest.applyVector(java.util.Vector)
        at java.lang.Class.getMethod(Class.java:1665)
        at cn.itcast.day2.GenericTest.main(GenericTest.java:88)//88行就是红字表的

求解答

评分

参与人数 1技术分 +1 收起 理由
菜小徐 + 1

查看全部评分

2 个回复

倒序浏览
把代码全放上来 看看
回复 使用道具 举报
GenericTest.class.getMethod("applyVector", Vector.class)这里出现了问题。建议你更换成
GenericTest.class.getDeclaredMethod("applyVector", Vector.class)来试试。一般默认的只能获取到公共的方法。私有的方法使用getMethod应该是获取不到的。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马