Editing my question because I realized better what I want:
Say we have List<A>
with bunch of instances of classes extending A each with its own unique properties.
Like in this example:
- class A has field int x, getter and setter.
- class B extends A, and also has field int y with its getter and setter.
- class C extends A, and also has field int z with its getter and setter.
I don't want to use downcasting and instanceof
when iterating the list.
I read this post which was interesting: https://softwareengineering.stackexchange.com/questions/245263/how-to-avoid-downcasting
What is the right approach?
Thanks