How to have an arrailist as an argument to common objects?

I have a method for removing an object from a list, this is used to create listView, so the object is deleted using the index of the element listView. But I want this method to work for several types of objects, i.e. I have more than one listView.

public void removeFromList(ListView<Label> listView, ArrayList<objects?> arrayList){
        int minus = listView.getSelectionModel().getSelectedIndex();
        arrayList.remove(minus);
        listView.getItems().remove(minus);
}
+4
source share
1 answer

Use wildcard binding:

ArrayList<?> arrayList

This allows you to pass any method ArrayList.

+7
source

Source: https://habr.com/ru/post/1695338/


All Articles