Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have an arraylist of general objects as argument?

I have a method to remove an object from the list, this is used to create a listView so the object is removed using the index of the listview item selected. But I want the 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);
}
like image 707
Billies Wesley Avatar asked Mar 07 '23 14:03

Billies Wesley


1 Answers

Use the wildcard bound:

ArrayList<?> arrayList

This allows you to pass any ArrayList to the method.

like image 70
Andy Turner Avatar answered Mar 15 '23 11:03

Andy Turner