Search code examples
javalistinitializationejb

Cannot instantiate the type List<Product>


I have the following code:

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

The error:

Cannot instantiate the type List<Product>

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


Solution

  • 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>();