I have a vector which contains several elements consisting of a user defined object. Now I'd like to add objects of ANOTHER user defined object. I know you can do this in C++, but can you also do this in java? My main question is once I add elements of this new objectt ype, how do I go through the vector element by element checking to see what type of object is stored in there. If I have the first user defined object in the slot, then I need to do a certain set of operations to it and if I have the 2nd user defined object in the slot then I need to do another set of operations to it....thanks for all the help!
Originally posted by amr amr:
thanks for the help but it still hasnt answered my question...perhaps I wasnt clear...I want to know how exactly you check to see what type of object is stored in the element...in other words in those if statements in the code how do i determine if elm is an instance of class1 or class2....i hope this clarifies my question better...thanks again...
To check the type of an object use the instanceof operator, I guess you missed it up in Jean-Francois post.
Originally posted by Jean-Francois Briere:
// verify its class type
if (elm instanceof ClassName1)
ClassName1 elm1 = (ClassName1)elm;
[ March 28, 2004: Message edited by: Vicken Karaoghlanian ]