Q1.jvm里是不是本来就装载了primitive types的class object?
Q2.int.class.newInstance()得到的是什么类?
为什么下面这段代码什么都没打印出
Class cl;
try {
cl = int.class;
Object m = cl.newInstance();
System.out.println(m.getClass().getName());
}catch(Exception e){ }大家一起看看

解决方案 »

  1.   

    //这个倒是可以打印出int
    cl = int.class;
    System.out.println(cl.getName());
      

  2.   

    啊 第二个问题我知道了
    通过查api文档得知
    class类里的newInstance()
    Throws:
        InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.我补过了异常,却没print a stack trace... 吃了一堑不过第一个还是不明白,为什么会有primitive types的class object?class object不是制造对象用的吗,primitive types又不是对象,怎么会有int.class之类的东西,难道声明一个int型也用到了int.class
    还是int.class只用来做RTTI?  实验室要关门啦,回去再看看thinking in java的Detecting Types这章...看看我的猜想对不对