How can i instanciate the only constructor that my classes have and how can i parse using reflection api? //btw the real class uses Enum to get most of the data.
import java.lang.reflect.*;
import java.util.*;
import javax.swing.table.*;
public class Reflec{
String[][] param={ {"John", "48"}, ... };//info read from file
Class[] cl={ Person.class ,... };//My classes I want to instantiate
paramClass[] pcl={{String.class, Integer.class}, ...};
public Reflec(int i){ //After constructing I know all I need to instantiate
this.i=i; //So now I know my info as cl[i], paramClass[i], and the param[i]
}
//how can I Instance of the class in cl[i] with the params on param[i] previusly parsed as
//paramClass requires for integers.
}
Thanks, but the parse is still missing:
Constructor<?> ctor =cl[i].getConstructor( paramClass[i] ); //excellent
//I am still struggling to parse the Array to Object array
//parsedArray = new Object={"John", 48}; not shure if that works and interpret 48 as Integer.
//Object object = ctor.newInstance( parsedArray );