无法实例化类型列表<产品> [英] Cannot instantiate the type List<Product>

查看:299
本文介绍了无法实例化类型列表<产品>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

List<Product> product = new List<Product>();

错误:

Cannot instantiate the type List<Product>

产品是我的EJB项目中的一个实体。为什么我得到这个错误?

Product is an Entity in my EJB project. Why I'm getting this error?

推荐答案

列表是一个界面。接口无法实例化。只有具体的类型可以被实例化。您可能希望使用 ArrayList ,这是列表界面的实现

List is an interface. Interfaces cannot be instantiated. Only concrete types can be instantiated. You probably want to use an ArrayList, which is an implementation of the List interface.

List<Product> products = new ArrayList<Product>();

这篇关于无法实例化类型列表&lt;产品&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆