在JDK1.5中,引入了对primitive type与其对应的wrapper的自动转换功能,通常都能很好的运作,但是在反射的层面却没有实现自动转换功能。
如果定义的的方法签名如下:
- publicvoiddoSth(Stringarg0,intarg1,Integerarg2)
要使用反射的方式获取该Method的引用时:
- xxx.class.getMethod("doSth",newClass[]{String.class,int.class,Integer.class})
其中,newClass[]{String.class,int.class,Integer.class})的int.class与Integer.class不能互换,否则无法取得该方法的引用。