One of the conditions of the problem: In the Cat class, add the public static variable cats (ArrayList<Cat>) public . I understand it like this:
public static int cats; Q: What is (ArrayList<Cat>) ?
One of the conditions of the problem: In the Cat class, add the public static variable cats (ArrayList<Cat>) public . I understand it like this:
public static int cats; Q: What is (ArrayList<Cat>) ?
ArrayList<Cat> - это список, в котором лежат объекты класса Cat ArrayList is one of the implementations of the List interface (list) which is based on a regular array.
There are other implementations of this interface: for example, LinkedList (Linked List).
Learn more about the topic of collections in Java.
About generics you wrote in the comments.
Imagine an array that behaves like an object. That is, it has methods that allow you to add / remove something in yourself. This is such a tricky array called ArrayList .
So that you can add only Сat to an ArrayList , you limit yourself:
ArrayList<Сat> With such a construction, it is impossible to put anything in ArrayList except for instances of class Сat .
For example, restrict String :
ArrayList<String> Nothing but rows put.
Source: https://ru.stackoverflow.com/questions/614046/
All Articles
public static ArrayList<Cat> cats = new ArrayList<>();. Or sopublic static List<Cat> cats = new ArrayList<>();What doesintdo with anything? - Sergey