Java : A List of type interface

标签 java list interface

我正在尝试使用以下代码:

List<ItemInterface> interfaceList = new List<ItemInterface>();

Eclipse报错:Cannot instantiate the type List

这段代码有什么问题?

最佳答案

List 本身就是一个接口(interface)。你需要使用类似的东西:

List<ItemInterface> interfaceList = new ArrayList<ItemInterface>(); 

关于Java : A List of type interface,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7664986/

相关文章:

java - Jersey:mysql java.lang.ClassNotFoundException:com.mysql.jdbc.Driver 虽然包含在内

java - Spring - 使用 applicationContext.xml 和 XXXXX-servlet.xml

Java:难以理解接口(interface)的用途?

java - 如何在 Fragment 和适配器之间创建接口(interface)?

c# - 通用列表 : The type arguments for method cannot be inferred from the usage in lambdas

java - 使用冒泡法对数组进行升序排序。其他数组则位于不同的索引处

java - 如何从 SQLite 数据库中删除特定行

python - 使用对象列表对嵌套列表进行排序

javascript - Jquery - 将类添加到列表,同时从以前单击的列表中删除

java - 在单独的方法中使用在构造函数中创建的列表