I need to find if my current class has method with a parameter that either its type is Integer of its generic type is Integer.
I wrote the following in main:
public static main(String[] args){
Class<?> clazz = Class.forName("Test");
Class<?> lookingForClass = Integer.class;
Method[] method = clazz.getMethods();
for (int i = 0; i < method.length; i++) {
Type[] types = method[i].getGenericParameterTypes();
for (int j = 0; j < types.length; j++) {
Type type = types[j];
Class<?> result = type.getClass();
if (type instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) type;
Type[] fieldArgTypes = pt.getActualTypeArguments();
result = (Class<?>) fieldArgTypes[0];
}
if (result instanceof lookingForClass)
System.out.println("found it");
}
}
}
public static void findTowInArray(List<Integer> A) {
}
public static void findTowInArray(Integer A) {
}
public static void findTowInArray(String A) {
}
However I get a compilation error on if (result instanceof lookingForClass)
Incompatible conditional operand types Class<capture#6-of ?> and lookingForClass
What is wrong?