A
Adam Lipscombe
Folks,
I am converting existing code to use paramaterised generic collections.
I need to add 2 different object types to a common list. Both object are interfaces that extend a
common interface.
e..:
Assuming MyType, MyTypeA, MyTypeB, where MyTypeA and MyTypeB are interfaces that extend interface
MyType.
List<? extends MyType> list = getMyTypeAList();
List.addAll(getMyTypeBList());
The compiler barfs at the addAll() as follows:
"The method addAll(Collection<? extends capture#1-of ? extends Bean>) in the type List<capture#1-of
? extends Bean> is not applicable for the arguments (List<MyTypeB>)"
I dont understand why as interface MyTypeB extends interface MyType.
I have also tried it with:
List<MyType> = getMyTypeAList();
List.addAll(getMyTypeBList());
This time the compiler complains "Type mismatch: cannot convert from List<MyTypeA> to List<Bean>"
What am doing to wrong? How to do this?
TIA - Adam
I am converting existing code to use paramaterised generic collections.
I need to add 2 different object types to a common list. Both object are interfaces that extend a
common interface.
e..:
Assuming MyType, MyTypeA, MyTypeB, where MyTypeA and MyTypeB are interfaces that extend interface
MyType.
List<? extends MyType> list = getMyTypeAList();
List.addAll(getMyTypeBList());
The compiler barfs at the addAll() as follows:
"The method addAll(Collection<? extends capture#1-of ? extends Bean>) in the type List<capture#1-of
? extends Bean> is not applicable for the arguments (List<MyTypeB>)"
I dont understand why as interface MyTypeB extends interface MyType.
I have also tried it with:
List<MyType> = getMyTypeAList();
List.addAll(getMyTypeBList());
This time the compiler complains "Type mismatch: cannot convert from List<MyTypeA> to List<Bean>"
What am doing to wrong? How to do this?
TIA - Adam