org.springframework.beans.factory.config.ConfigurableBeanFactory.destroySingletons()
在看Spring源码时,发现上面面接口中的方法,在eclips中通过Ctrl+T查看继承关系时,没有找到实现该方法的类,但是又有很多类实现了ConfigurableBeanFactory接口,并且存在很多处对该方法的调用。
在全部代码中搜索后发现,DefaultSingletonBeanRegistry类中有一个方法的签名和接口中的方法相同。
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons()
观察两个类的继承体系后发现,实现了ConfigurableBeanFactory接口的类,都继承了DefaultSingletonBeanRegistry类。由于父类中的方法与接口中的方法签名相同,子类继承了该方法,相当于实现了接口中的方法。
另外写了几个类验证了下,发现是这个原因。不知道为什么采用这种方法,太不清晰了。
public interface DemoInter {
String getName();
}
public class Super{
public String getName(){
return this.getName();
}
}
public class SubToIml extends Super implements DemoInter{
public static void main(String[] args) {
SubToIml sub = new SubToIml();
sub.getName();
}
}