为什么大多数例子使用的ArrayList例子、ArrayList

2023-09-05 01:57:56 作者:不傷不該傷旳吢

开发Java,你一直获悉,其最好使用List接口作为列表存储在该变量的类型,来创建一个ArrayList。像这种

 名单,其中,字符串> myList上=新的ArrayList<字符串>();
 

然而,通过查看了很多包含在束中的机器人的例子,他们通过使用类创建的列表

 的ArrayList<字符串> myList上=新的ArrayList<字符串>();
 

是否有任何理由为什么这样做?难道是更快,更轻什么明确设置类? 解决方案 ArrayList常用方法总结

在资源受限的环境下,如该机器人是专为手机,这是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.

 
精彩推荐
图片推荐