0

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.

Zahid Ali
  • 3
  • 2
  • 1
    Your `myCart.getItemsList` returns a raw not-parameterized `List`. You can suppress the warning by adding `@SuppressWarnings("unchecked")` just right before the assignment statement. – terrorrussia-keeps-killing Dec 01 '20 at 06:10
  • @fluffy thank you so much for the quick reply it worked for me but what if I do not want to suppress it. is there any other option? – Zahid Ali Dec 01 '20 at 06:19
  • 1
    Make the `getItemsList` return `ArrayList`. See more at https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it – terrorrussia-keeps-killing Dec 01 '20 at 06:21

1 Answers1

0
  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>.
Chakrit W
  • 322
  • 3
  • 11