I am using an Arraylist to hold heterogeneous data…a mix of String, int and class objects (These objects could be instances of any class I’ve defined.). I’ve initialised the ArrayList as ArrayList<Object> = new ArrayList<Object>.
But I think I’ve heard ppl saying that directly referring to the Objects is sth. bad/undesirable? I’m referring to the objects because I can’t find any suitable generics to use in my case. Is it ok to use or are there any suitable generics? (I’m relatively new to Java)
Use different list for each type and keep those lists in a map and you can use the class object as the key so it wont mix up and easy to access.
EDIT:
P.S: You will still get an unchecked warning when you retrieve the list from the map if you want to add new object into the list.