可能重复:
What is the benefit of polymorphism using Collection interface to create ArrayList object?优势的ArrayList
什么是如果静态类型parameterGroupList
超过ArrayList<User> parameterGroupList = new ArrayList<User>();
可能重复:
What is the benefit of polymorphism using Collection interface to create ArrayList object?优势的ArrayList
什么是如果静态类型parameterGroupList
超过ArrayList<User> parameterGroupList = new ArrayList<User>();
定义一个ArrayList作为 Collection<User> parameterGroupList = new ArrayList<User>()
的优势Collection<User>
,parameterGroupList
的用户将只使用操作员可以在Collection<User>
中找到并避免特定于ArrayList
的操作。因此,将来您可以更轻松地将ArrayList
替换为其他一些收藏,例如LinkedList
。
干脆把与使用运行时多态性的优势。
你问什么是Java 101的问题。
'Collection'是一个接口(无法保证运行时间界限和一些可选的方法)。 [还有什么实现它](http://docs.oracle.com/javase/6/docs/api/java/util/Collection.html)? – 2012-11-30 17:19:28
设计到接口,有效的java – NimChimpsky
对我来说,“有趣”(fsvo)的问题是,何时在List上使用“Collection”? – 2012-11-30 17:22:09