为什么大多数例子使用的ArrayList [英] Why are most of the examples using ArrayList

查看:290
本文介绍了为什么大多数例子使用的ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

 的ArrayList<字符串> myList上=新的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.

这篇关于为什么大多数例子使用的ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆