Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是弹簧新手,正在阅读在线弹簧参考。使用构造函数注入 (CI) 的优点之一是因为 CI 是不可变的?我知道这意味着它不能被修改。但是这是怎么发生的,请任何简单的例子来说明 CI 如何促进不变性?谢谢
这是一个不可变的 bean,感谢 CI
class B1 { private final int x; B1(int x) { this.x = x; } }
上下文.xml
<bean id="b1" class="test.B1"> <constructor-arg value="1"/> </bean>