I know this question is answered some time. But all the time the parameter is an object. Thats what I want to replace:
if (s.equals("A")) { add (obj = new A(x,y)); }
if (s.equals("B")) { add (obj = new B(x,y)); }
if (s.equals("C")) { add (obj = new C(x,y)); }
I have this:
try
{
Class cl = Class.forName(s);
Constructor con = cl.getConstructor (x, y);
obj = con.newInstance(x, y);
}
but it expect x,y as a class, but its an int. How to do this>
ints then maybe trycl.getConstructor (int.class, int.class);Constructor con = c1.getConstructor((Integer) x, (Integer) y);