微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 标签在春天如何工作

我有收藏乐器;在我的SomeClass.java中,我在temp.xml文件中声明了SomeClass.java类的bean.在xml中,我将两个字符串对象添加到集合中.

我的问题是Collection是一个接口所以我无法实例化它而List也是一个接口所以我认为我们无法做到

 Collection

我想知道当我们在xml文件中使用list标签时java代码是如何工作的.意味着对象是存储在链表或arraylist还是某种类型的列表中?

最佳答案
这取决于ApplicationContext.每个实现可能不同,但您可以确定结果是List.编号documentation

Another custom namespace utility is for creating lists. The first bean
deFinition is identical to the Listfactorybean example except it’s a
little shorter and easier to read. The second bean deFinition is the
same except it uses the list-class attribute to specify what List
implementation to use. When the list-class attribute isn’t used,the
ApplicationContext will choose the implementation class.

检查implementation of ListFactoryBean,您可以看到,如果未提供特定的列表类型,则ArrayList是实例化的认列表实现.执行此任务的代码片段是:

if (this.targetListClass != null) {
    result = (List) BeanUtils.instantiateClass(this.targetListClass);
}
else {
    result = new ArrayList(this.sourceList.size());
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐