我有以下代码:
List<Product> product = new List<Product>();
错误:
Cannot instantiate the type List<Product>
Product
是我的 EJB 项目中的一个实体。为什么会出现此错误?
最佳答案
List
is an interface .接口(interface)不能被实例化。只能实例化具体类型。您可能想使用 ArrayList
,是List
接口(interface)的实现。
List<Product> products = new ArrayList<Product>();
关于java - 无法实例化类型 List<Product>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7960149/