lundi 26 octobre 2015

Parameter passing to constructor in Java Instantiation

I ran into the following problem with instantiating a Java class:

Say, I have a defined class with constructor:

public A(Integer num, String val, ArrayBlockingQueue<Float> q);

I'm trying to instantiate A as follow:

Class<?> myA = Class.forName(<package_name> + "A");
Class[] param = {Integer.class, String.class, ArrayBlockingQueue.class};
Constructor<?> cons = myA.getConstructor(param);

Yet at runtime, the program thows "NoSuchMethodException":

A.<init>(java.lang.Integer, java.lang.String, java.util.concurrent.ArrayBlockingQueue)

Any pointer would be much appreciated. Thank you!





Aucun commentaire:

Enregistrer un commentaire