Java inheritance question

Posted by user247866 on Stack Overflow See other posts from Stack Overflow or by user247866
Published on 2010-06-10T18:00:09Z Indexed on 2010/06/10 18:02 UTC
Read the original article Hit count: 106

Filed under:
|
|

So I have 3 classes.

Abstract class A 

Class B extends class A

independent Class C

In class D that contains the main method, I create a list of instances of class B

List<B> b =  method-call();` // the method returns a list of instances of class B

Now in class C I have one method that is common to both A and B, and hence I don't want to duplicate it. I want to have one method that takes as input an instance of class A, as follows:

public void some-method(LIst<A> a)

However, when I do:

C c = new C().
c. some-method(b)

I get an error that some-method is not applicable for the argument List, instead it's expecting to get List.

Is there a good way to fix this problem? Many thanks!

© Stack Overflow or respective owner

Related posts about java

Related posts about inheritance