protectedbooleancheckGenericTypeMatch(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor){ //目标类型,也就是List<Throwable>类型 ResolvableType dependencyType = descriptor.getResolvableType(); //如果目标类型不存在泛型则直接返回匹配 if (dependencyType.getType() instanceof Class) { // No generic type -> we know it's a Class type-match, so no need to check again. returntrue; } //.. //从创建方法中获取候选bean类型,这里是Queue<String>,如果和目标类型不匹配会返回null,这里会返回null targetType = getReturnTypeForFactoryMethod(rbd, descriptor); //如果targetType为空,则用下面方法获取对象类型,这里会丢失泛型信息,结果为A<?> Class<?> beanType = this.beanFactory.getType(bdHolder.getBeanName()); targetType = ResolvableType.forClass(ClassUtils.getUserClass(beanType)); //这里会把类型缓存起来,当b对象注入的时候,会发现targetType为A<?>,和目标Queue<String>不同,注入失败 if (cacheType) { rbd.targetType = targetType; } //这里是处理通用泛型的情况,如上面的?,但是默认descriptor.fallbackMatchAllowed()返回false,这里不过多讨论 if (descriptor.fallbackMatchAllowed() && (targetType.hasUnresolvableGenerics() || targetType.resolve() == Properties.class)) { // Fallback matches allow unresolvable generics, e.g. plain HashMap to Map<String,String>; // and pragmatically also java.util.Properties to any Map (since despite formally being a // Map<Object,Object>, java.util.Properties is usually perceived as a Map<String,String>). returntrue; } //A<?>并不是List<Throwable>子类型,所以返回false。 return dependencyType.isAssignableFrom(targetType); }