I have a bit of confusion in the following:
class Foo{
private ArrayList<Obj1> obj1List;
private ArrayList<Obj2> obj2List;
/* constructor */
...
public void push(?){
if(the object is of type Obj1)
push into obj1List (object)
if(the object is of type Obj2)
push into obj2List (object)
}
How can I do such a thing with the Push function, that it would identify the object type itself, without using instanceof (casting) or using (Object obj) as its’ parameter? I need to it to know into which arraylist to push!
The easiest method is to have two overloads: