In regards to your "very dodgy pseudo code" you would need to use the instanceof operator and then cast the object to the subclass.