1

I needed an Arraylist which can hold multiple types of content, browsing some questions on Stackoverflow, I found that ArrayList<Object> arrayList = new ArrayList<>(); can do the trick. But when I tried to use the arraylist it throws an casting error.

This is my code. (error commented in 5th line)

private ArrayList<Object> arrayList = new ArrayList<>();

public RecyclerViewAdapter(Context context, ArrayList<CardSetterGetter> arrayList, ArrayList<String> favouriteItemList, int totalCount) {
    this.context = context;
    this.arrayList = arrayList; //Incompatible types.  Required: ArrayList<java.lang.object>;    found: ArrayList<com.comp.app.modal.CardSetterGetter>
    this.favouriteItemList = favouriteItemList;
    this.totalCount = totalCount;

}
Ishan hrx
  • 403
  • 8
  • 19

0 Answers0