我尝试使用下面的代码:的Java:接口类型的列表
List<ItemInterface> interfaceList = new List<ItemInterface>();
的Eclipse提供了一个错误:无法实例类型列表
什么是错的代码?
我尝试使用下面的代码:的Java:接口类型的列表
List<ItemInterface> interfaceList = new List<ItemInterface>();
的Eclipse提供了一个错误:无法实例类型列表
什么是错的代码?
列表是一个接口本身。你需要使用类似:
List<ItemInterface> interfaceList = new ArrayList<ItemInterface>();
List<T>
是一个接口,而不是一个类。
您可能意思是new ArrayList<T>()
。
List<T>
是Java的接口,你必须使用类,implement List
之一。
下面是从Java教程的教训/教程: http://download.oracle.com/javase/tutorial/collections/interfaces/
这里的List
Java文档,用的Java API中实现它的类的列表:http://download.oracle.com/javase/6/docs/api/java/util/List.html
对你来说,你可能想使用ArrayList<T>
,所以:
import java.util.ArrayList;
...
List<ItemInterface> interfaceList = new ArrayList<ItemInterface>();
另请注意,有时搜索返回的错误将是生产性的(并且比等待我们更快,虽然...我们很快;) –