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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李会成 中级黑马   /  2013-1-28 15:46  /  1053 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 李会成 于 2013-2-18 11:43 编辑

  1.         int [] a1 = new int[2];
  2.         int [] a2 = new int[3];
  3.         int[][] a3 = new int[2][3];
  4.         String [] a4 = new String[2];
  5.         System.out.println(a1.getClass() == a2.getClass());
  6.         System.out.println(a1.getClass()==a3.getClass());//出错 Incompatible operand types Class<capture#8-of ? extends int[]> and Class<capture#9-of ? extends int[][]>
  7.         System.out.println(a1.getClass()==a4.getClass());//出错 Incompatible operand types Class<capture#10-of ? extends int[]> and Class<capture#11-of ? extends String[]>
复制代码
照理来说,每一种类的字节码对应下来应该只是Class类的一个实例对象,那为什么还要对Class类定义泛型呢?比如String.class 的类型是Class<String>,这样有什么意义?

评分

参与人数 1技术分 +1 收起 理由
Rancho_Gump + 1

查看全部评分

3 个回复

倒序浏览
编译器版本不一样。
换成1.4的版本就可以编译通过
回复 使用道具 举报
编译器版本问题,1.5以上才支持泛型
回复 使用道具 举报
代码就一部分,最后的结果不知道。
最后是比较。看下“==”和“equals”的却别。==改成equals全部通过。不知道和楼主的题意是否相符合。
        int [] a1 = new int[2];
        int [] a2 = new int[3];
        int[][] a3 = new int[2][3];
        String [] a4 = new String[2];
        System.out.println(a1.getClass().equals(a2.getClass()));
        System.out.println(a1.getClass().equals(a3.getClass()));
        System.out.println(a1.getClass().equals(a4.getClass()));
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马