Hello all :) I'm trying to chose the right constructor in a class. Here is the code:
Constructor[] constructors = targetClass.getConstructors();
Constructor goodConstructor = null;
for (Constructor constructor : constructors) {
Class[] parameterTypes = constructor.getParameterTypes();
if (parameterTypes.length = 1 && parameterTypes[0].equals(Map.class)) {//here
goodConstructor = constructor;
}
}
I want to switch from Map.class
to Map<String, String>.class
. I vaguely remember that generics are for compile time only, so this is why the compiler is complaining. How can I check at runtime that the class has the right constructor?
Best regards