我怀疑使用Spring时将在下面提到的场景中创建的实例数量:
bean配置是这样的
<bean id="a" class="A">
<property name="b" ref="b"/>
</bean>
<bean id="b" class="B" scope="session"/> or
<bean id="b" class="B" scope="prototype"/>
Run Code Online (Sandbox Code Playgroud)
默认情况下,bean"a"具有singleton scope.因此,有一个单例bean,它引用了一个具有会话范围或原型范围的bean.
在这种情况下,如果同时有2个应用程序请求,那么将创建多少个A实例以及将创建多少个B实例?
如果有人可以解释这是如何工作的,那将会有很大的帮助吗?
谢谢,Divya
我是java中Generics的新手.我尝试过以下方法:
Entity class:
public class Box<T> {
private List<T> boxList;
public List<T> getBoxList() {
if (this.boxList == null)
this.boxList = new ArrayList<T>();
return this.boxList;
}
public void setBoxList(List<T> boxList) {
this.boxList = boxList;
}
}
Test class:
public class Client {
public static void main(String[] args) {
Box box = new Box();
box.getBoxList().add(1);
box.getBoxList().add("one");
System.out.println(box.getBoxList());
Box boxInt=new Box<Integer>();
boxInt.getBoxList().add("apple");
System.out.println(boxInt.getBoxList());
}
}
Run Code Online (Sandbox Code Playgroud)
虽然我的boxInt是Integer类型,但BoxList列表仍然接受"apple".我希望它在编译时抛出一个错误.任何有关如何工作的帮助将非常感谢.
谢谢,Divya