我需要查找我当前的类是否具有带有参数的方法,其类型为整数,其泛型类型为整数。
我主要写了以下内容:
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) {
}
但是我得到一个编译错误if (result instanceof lookingForClass)
Incompatible conditional operand types Class<capture#6-of ?> and lookingForClass
怎么了?