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.
这些线有什么区别吗?
1. @Autowired private MyClass obj; 2. @Autowired private MyClass obj = null; 3. @Autowired private MyClass obj = new MyClass();
显然,第三个是不好的做法。
请解释。
没有区别:无论您分配给它什么,实例都是由容器注入的。
选项 1 是最好和最常用的样式。