List vs ArrayList [英] List vs ArrayList
本文介绍了List vs ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
List<EventHandler<E>> listeners = new List<EventHandler<E>>();
为什么上面的行不符合:
Why the line above fails with:
无法实例化类型
列表< EventHandler< E>>
$
$ b
But this one works:
ArrayList<EventHandler<E>> listeners = new ArrayList<EventHandler<E>>();
推荐答案
正确的方法是:
$ b
The proper way is:
List<EventHandler<E>> listeners = new ArrayList<EventHandler<E>>();
- 通过其接口引用一个对象(
List
) - 实例化对象及其具体类型(
ArrayList
)(接口不能实例化) - refer to an object by its interface (
List
) - instantiate the object with its concrete type (
ArrayList
) (interfaces can't be instantiated)
这篇关于List vs ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文