norty's stuff was simple. This gets a bit more involved.
Ok, so i have an arraylist that contains references to two different types of object. Both of these objects extend from the same superclass.
My question is, if i use casting while traversing the arraylist, can i cast each reference as the superclass or do i have to find a way to identify which object each reference is and cast in that specific object to find the value of an instance variable that's inherited from the superclass anyway?
PS. I'm aware that casting is pretty pointless since java 5, but i need do it this way for this work. Don't ask why.
Ok, so i have an arraylist that contains references to two different types of object. Both of these objects extend from the same superclass.
My question is, if i use casting while traversing the arraylist, can i cast each reference as the superclass or do i have to find a way to identify which object each reference is and cast in that specific object to find the value of an instance variable that's inherited from the superclass anyway?
PS. I'm aware that casting is pretty pointless since java 5, but i need do it this way for this work. Don't ask why.