I’m trying to make a function that takes one of many classes that extends Foo, and return a new instance of that object in its Class, not a new instance of Foo.
I’m sure this is a common issue. Is there any good examples out there?
I have never used a class as an input parameter, only members of a class. Based on what I have searched for, this should be possible to do?
Are you passing a
Classobject as the parameter, or in instance of a subclass ofFoo?The solution is almost the same in either case, you use the newInstance method on the Class object.
If you need constructor args you can use the Class getConstructor method and from there the Constructor newInstance(…) method.