I've got set of classes: TestClass1, TestClass2 and TestClass3. All those classes inherits from class MainTestClass. Classes TestClass1, TestClass2 and TestClass3 has different constructors. For example:
TestClass1(String s)
TestClass2(Integer i)
TestClass3(Double d)
Classes can have more than one constructor - each different from others.
Now I want to randomly create instances of these classes and store them in List. To do that, I store Class objects of TestClass1, ... using TestClass1.class, ... in a List. Then, I get for example first constructor of each class, that has non-zero parameters count. Now, when I want to create object using newInstance() method, I don't know types and count of arguments to pass to this specific constructor.
Is it possible to achieve something like this using reflection? I have been thinking about something like
setConstructorArgument(int number, Object value)
or
setConstructorArguments(Object[] arguments)
Do similar methods exists in Java?
Object... initargswithObject[] initargs. You can post your comment as answer and I'll accept it as correct one. Thanks :)