Say I got classes A, B, C such that B extends A and C also extends A
Now I have 2 different classes, let's give them MyClassB and MyClassC with a member ArrayList<B> and ArrayList<C> respectfully.
Since many of the actions in MyClassB and MyClassC same and are performed only for another type of ArrayList, I wanted to create a new abstract class MyClassA that will implement the same actions on ArrayList<A> for both classes, since A is the common part, the action of which the same way.
Therefore, I tried to create a method in the new MyClassA class, which receives the list as an argument and must take an action in this list. However, I cannot pass an ArrayList<B> method in which it expects an ArrayList<A> .
So what can I do to keep the same actions in a different class and not repeat the code in two different classes?
source share