且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用反射创建新对象?

更新时间:2023-11-30 12:55:34

您需要为此找到确切的构造函数。 Class.newInstance()只能用于调用nullary构造函数。所以写

You need to locate the exact constructor for this. Class.newInstance() can only be used to call the nullary constructor. So write

final Value v = Value.class.getConstructor(
   int.class, int.class, double.class).newInstance(_xval1,_xval2,_pval);