So I've read in some data from an XML:
String arg1Value;
String arg2Value;
String arg2TypeAsString;
String arg1TypeAsString;
and I want to create an object: ObjectType(arg1Type, arg2Type);
I'm trying this:
(ObjectType) Class.forName(arg1TypeAsString).getConstructor(arg1Type.class, arg2Type.class).newInstance(arg1Value, arg2Value)
But this gives me a noSuchMethodException: ObjectType.<init>(arg1Type, arg2Type)
Note that I'm trying to create different objects but they all extend from ObjectType and all their arguments extend from arg1Type and arg2Type respectively.
Given the specifications are a bit vague (no actual code), try the followings:
private
,protected
or default package modifier, if so, usegetDeclaredConstructor()
insteadObjectType
classSplit your statement on multiple lines: