起因在于使用了一个向ioc容器中注入的带有泛型声明的bean,然后在注入时使用了不同的泛型作为qualifier
@Autowired
private AggregationUtilBean<Integer, Integer> aggregationUtilBean;
@Autowired
private AggregationUtilBean<Student, Integer> aggregationUtilBean2;
根据spring ioc容器的bean注入原理, aggregationUtilBean和aggregationUtilBean2理所应当的是同一个bean,对象的内存地址应该相同,换言之,使用==比较的结果应该为true,那么事情是这么简单吗?
不出意外,编译报错了,因为两个对象的泛型签名不同,编译器默认二者不可能为同一个对象因此在编译阶段就进行报错(实际上注入的的确是同一个bean),为了绕过泛型签名的现在进行验证,我又注入了下面两个bean
@Autowired
private AggregationUtilBean<? extends Student, Integer> aggregationUtilBean;
@Autowired
private AggregationUtilBean<Student, Integer> aggregationUtilBean2;
这下两个对象可以使用==进行比较了,结果为true也符合预期。extends限界符的存在告诉编译器声明的可能是同一个对象因此这次可以使用==来进行对象内存值的比较。