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

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

问题描述

开发Java,你一直都知道最好通过使用List接口作为存储列表的变量的类型来创建一个ArrayList.像这样

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>();

但是,通过查看捆绑包中包含的大量 android 示例,他们使用 Class 创建了列表.

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?

推荐答案

在 Android 设计的手机等资源受限的环境中,最好避免使用 Interface,因为它涉及额外的虚函数调用.

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天全站免登陆