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

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

问题描述

我有以下代码:

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

错误:

Cannot instantiate the type List<Product>

Product 是我的 EJB 项目中的一个实体.为什么会出现此错误?

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

推荐答案

List 是一个接口.接口不能被实例化.只能实例化具体类型.您可能想使用 ArrayList,是List接口的实现.

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

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

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