Create new object using reflection?

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);

Leave a Comment