javaarraylistunsafeunchecked

Main.java uses unchecked or unsafe operations ArrayList<Product> cartItems = myCart.getItemsList();


I am getting the warning Note: Main.java uses unchecked or unsafe operations. in the following code

ArrayList<Product> cartItems = myCart.getItemsList();

How to remove this warning.


Solution

    1. Does your myCart.getItemsList() returns List or ArrayList, and does the type have parameter <Product>?
    2. You might consider using List<Product> cartItems, which should be sufficient in most cases, and make sure myCart.getItemsList() returns List<Product>.