Help solve the problem. I can not understand what my mistake. class ProductSearchSrvice to be in a separate class.

import java.util.List; import java.util.ArrayList; public class Lab10 { public static void main(String[] args){ List<ProductSearchSrvice> list = new ArrayList<>(); ProductSearchSrvice shop_1 = new ProductSearchSrvice("Rozetka"); ProductSearchSrvice shop_2 = new ProductSearchSrvice("OLX"); ProductSearchSrvice shop_3 = new ProductSearchSrvice("HIKVISION"); List.add(shop_1); List.add(shop_2); List.add(shop_3); } } class ProductSearchSrvice { private String name; public ProductSearchSrvice(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "ProductSearchSrvice{" + "name='" + name + '\'' + '}'; } } 
  • I did not get that. What is the problem? - Nastya Grant
  • Aah, I understood everything, what a big letter. Thank you very much. - Nastya Grant

1 answer 1

 List.add(shop_1); List.add(shop_2); List.add(shop_3); 

The List interface does not contain the static add() method that you are trying to call. However, the ArrayList implementation has this method, so you can call it as an instance method of the list