楼主 这没什么好纠结的啊, 谁说基本类型就没有Class吗, 你可以试试 int.class 看它返回什么, 
Class<Integer> clazz = int.class
即使这个不理解,那你也可想到它的封装类啊

解决方案 »

  1.   

    LS说了,基本类型也有对应的Class对象

    int.class
    long.class
    float.class
    double.class
    等等
      

  2.   

    没什么好纠结的,java中所有的都存在class,所以是什么类型就传什么类型的class就可以了
      

  3.   

    我以前没有看到过,我刚试了,int.class,Integer.class,void.class 都能通过编译,并显示出来。但还是理解不了。
    int 既然也是Class,那为什么还要设计其包装类呢?
      

  4.   

    因为包装类提供了一系列的操作方法,在一定程度上符合面向对象的规范。
    比如
    Integer i = 5; i.bitCount(); 使用 对象.方法 来操作

    int i = 5; 就没有 i.xxx 这样的方法调用了
      

  5.   

    楼主还是没有搞清楚int 和Integer的区别...
    int是基本类型
    Integer是包装类
    java1.5版本以后,提供了Integer和int的自动转换
    比如:int i=5;i.class的话,Java会自动把i转换成Integer类型
      

  6.   

    每个类都有一个class,getSimpleName试试…
      

  7.   

    正因为int 和 Integer 不一样,所以 Integer 易于理解,int 就难于理解。 我在前面的程序基础上,给User类加了两个属性:
    private Integer integer;
    private int id;再增加一构造函数:
    public User(Integer interger,int id)
    {
    this.integer=integer;
    this.id=id;
    }
    输出如下:
    public cs.ch51.User(java.lang.Integer int )可见在java内部,Integer he  int 不一样。
      

  8.   

    int.class和Integer.class本来就不同的两个对象啊
    最简单的判断方法就是
    System.out.println(int.class == Integer.class);输出肯定是false
    上面我说过了,需要包装类是因为包装类更符合面向对象的规则,因为基本类型没有相应的操作方法,只能依赖传统的操作符号来操作。

    int a = 0;
    System.out.println(a.getClass()); //这样是没法获得a的类型的

    Integer a = 0;
    System.out.println(a.getClass()); //这样就可以
    java是面向对象的,所以每种类型都有对应的Class对象
      

  9.   

        问题好像就在这,int 型不是引用类型,不能创建对象,就是我问的问题,怎么能把它放到Class[]数组里呢?
    我理解只有引用类型可以放到Class[]里啊,象 Integer, Long ,ArrayList,System,String 等等,int 不是引用类型,怎么也能放到那里呢?
        
      

  10.   

    既然int.class也是Class对象,那么当然就能放到Class[]数组里了
    比如
    Class[] c = new Class[]{int.class, double.class, long.class};
    这样没问题啊,int虽然不是引用类型,但是它也有个Class对象来维护int的信息,要注意类型和Class对象的区别,比如Integer是类型,Integer.class是Integer这个类型的Class管理对象
    你的例子中返回的Class[]是Class对象集合,不是类型集合,Class对象的getSimpleName方法返回的就是类型名字的文字串
      

  11.   

    那怎么解释void呢? 它好像不是基本类型,也不是引用类型,void.class也能放到Class[]里?