You can find it by going through List.class . For instance:
import java.util.*; import java.lang.reflect.*; public class Test { public static void main(String[] args) throws Exception { Class<?> clazz = MyClass.class; Constructor<?> ctor = clazz.getConstructor(List.class); ctor.newInstance(new Object[] { null }); } }
If you need to check for common parameter types, you can use getGenericParameterTypes and examine the returned Type[] . For instance:
Type[] types = ctor.getGenericParameterTypes(); System.out.println(types[0]);
You do not need to specify a type argument when calling getConstructor , because you cannot overload the constructor using parameters with only different parameters. These types of parameters will have the same type of erasure. For example, if you try to add another constructor with this signature:
public MyClass(List<String> structures)
You will receive an error message:
MyClass.java:7: name clash: MyClass(java.util.List<java.lang.String>) and MyClass(java.util.List<Structure>) have the same erasure
source share