首页 新闻 会员 周边

在spring注解通过FactoryBean创建bean,怎么区分A b = new B();A c = new C();?怎么实现?

0
[已解决问题] 解决于 2020-04-08 11:13

interface A {
void say();
}
class B implements A {
void say(){System.out.println('B');}
}
class C implements A{
void say(){System.out.println('C');}
}
public class Test{
public static void main(String[] args) {
A b = new B();
b.say();
A c = new C();
c.say();
}
}

黑仔002的主页 黑仔002 | 菜鸟二级 | 园豆:204
提问于:2020-03-30 22:09
< >
分享
最佳答案
0

spring 原理等很多资料涉及这个问题,IOC DI的机制
https://blog.csdn.net/w_linux/article/details/80063062 这也是一个例子

奖励园豆:5
2012 | 高人七级 |园豆:21230 | 2020-03-31 08:22

谢谢

黑仔002 | 园豆:204 (菜鸟二级) | 2020-04-08 11:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册