为什么大多数例子使用的ArrayList [英] Why are most of the examples using ArrayList
问题描述
开发Java,你一直获悉,其最好使用List接口作为列表存储在该变量的类型,来创建一个ArrayList。像这种
名单,其中,字符串> myList上=新的ArrayList<字符串>();
然而,通过查看了很多包含在束中的机器人的例子,他们通过使用类创建的列表
的ArrayList<字符串> myList上=新的ArrayList<字符串>();
是否有任何理由为什么这样做?难道是更快,更轻什么明确设置类? P>
在资源受限的环境下,如该机器人是专为手机,这是preferrable避免使用接口,因为它涉及到额外的虚拟函数调用。
Developing Java, you have always learned that its best to create an ArrayList by using the List interface as the type for the variable the list is stored in. Like this
List<String> myList = new ArrayList<String>();
However, by looking at a lot of the android examples that is included in the bundle, they have created the list by using the Class.
ArrayList<String> myList = new ArrayList<String>();
Is there any reason why this is done? Is it faster, lighter or something to explicitly setting the Class?
In resource constrained environment like the phones that Android are designed for, it's preferrable to avoid using Interface, since it involves additional virtual function call.
这篇关于为什么大多数例子使用的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!