【问题标题】:What is the Advantage of creating ArrayList in java by the below mentioned way [duplicate]通过下面提到的方式在java中创建ArrayList有什么好处[重复]
【发布时间】:2015-02-20 10:15:42
【问题描述】:

我是 Java 新手。创建ArrayList by:
List<String> a = new ArrayList<String>;
有什么好处或不同 结束
ArrayList<String> b = new ArrayList<String>();

【问题讨论】:

  • 在第一种情况下,a 可以接受 ArrayListLinkedList 等,前提是它是 List
  • 请注意,这不仅仅针对 ArrayList 或 List。

标签: java list arraylist collections


【解决方案1】:

您正在将代码与接口的特定实现解耦,请参阅此答案以获取更多详细信息: Polymorphism: Why use "List list = new ArrayList" instead of "ArrayList list = new ArrayList"?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2012-11-25
    相关资源
    最近更新 更多