System.out.println(new Integer(0).getClass().newInstance());
//或者这样写都不对
Integer.class.newInstance()

解决方案 »

  1.   

    因为 Integer 没有 默认的构造器,无法直接调用newInstance()
      

  2.   


    对头 Integer貌似有一个构造器new Integer(int i);所以你可以这样写
    try {
    System.out.println(Integer.class.getConstructor(int.class).newInstance(1));
    } catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (SecurityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InstantiationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
      

  3.   


    public class Test {
    public static void main(String[] args) {
    Class<Integer> c = Integer.class;
    try {
    int var = c.getConstructor(int.class).newInstance(111);
    System.out.println(var);
    } catch(Exception e) {
    e.printStackTrace();
    }
    }
    }
      

  4.   

    Integer没有无参数的public构造器啊。 所以不行咯。