51,410
社区成员
发帖
与我相关
我的任务
分享


/**
* Returns a {@code Constructor} object that reflects the specified
* public constructor of the class represented by this {@code Class}
* object. ....
*/
只能获取public 的constructor
// getConstructor只能获取public的构造方法
// Constructor constructor = c.getConstructor(int.class, String.class, Float.class);
Constructor declaredConstructor = c.getDeclaredConstructor(int.class, String.class, Float.class);
declaredConstructor.setAccessible(true);
Object obj = declaredConstructor.newInstance(10, "心态不好", 5.26f);
System.out.println(obj);