This has been solved! Look at the end of this post.
I'm having some trouble here with polymorphism, as I need to access methods in a subclass from an array of superclass objects.
This method is called parseCommand(Command c);
The method exists in the superclass and is overridden in the subclasses.
I'm using a LinkedList<Entity> with all the entities in the game.
There are (Will be) several objects of a class in this list which extends entity. The issue here is that I want to be able to access the parseCommand method in the subclass, not in the entity class.
I can do this with a simple typecast, like this:
However, I'm using multiple subclasses in this LinkedList<Entity> collection. I want to be able to do something in the lines of:
Is there a way to do this?
Looks like it was a logical error on my end! It works exactly as I intended, it seems to use the override in the subclass automatically.
If you came here for the same reason as me, assume it works and see if you can find any errors beyond the scope of typecasting issues.
Edited 7 Years Ago by Acegikmo: n/a