问题描述
import java.lang.reflect.Constructor;import java.lang.reflect.InvocationTargetException;public class Hello {private Integer h;public Hello(int... _t) {int _h = 0;for (int i : _t) {_h += i;}h = new Integer(_h);}public void say() {System.out.println("Hello World! " + h);}public static void main(String[] args) {try {Class<?> clazz = Class.forName("Hello");Constructor<Hello> c = (Constructor<Hello>) clazz.getConstructor(_________);Hello h = (Hello)c.newInstance(3,4,5);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SecurityException e) {e.printStackTrace();} catch (NoSuchMethodException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (InstantiationException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}}Constructor<Hello> c = (Constructor<Hello>) clazz.getConstructor(_________);这个地方怎么写?
解决方案
这个要变一下才行int [] a = new int[] {3,4,5}; try { Class<?> clazz = Class.forName("Hello"); Constructor<Hello> c = (Constructor<Hello>) clazz.getConstructor(int[].class); Hello h = (Hello)c.newInstance(a); h.say(); } catch.......