加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – 标签在春天如何工作

发布时间:2020-12-15 01:38:34 所属栏目:大数据 来源:网络整理
导读:我有收藏乐器;在我的SomeClass.java中,我在temp.xml文件中声明了SomeClass.java类的bean.在xml中,我将两个字符串对象添加到集合中. 我的问题是Collection是一个接口所以我无法实例化它而List也是一个接口所以我认为我们无法做到 Collection 我想知道当我们在

我有收藏乐器;在我的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());
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读