I can't tell for sure why this does not work. The provided information
is hard to interpret. Please send some source code. What I would think
can work, though, is if you make MyTypeA and MyTypeB subclasses of a
common superclass implementing the required interface. You would then
have a collection of instances of this superclass. Did you consider that
option? It seems to be a classical case of inheritance.
Håkan Lane
>> Please send some source code.
Here it is:
List<Claim> claimList = ClaimBO.getIncompleteClaimsList(user);
List<? extends Bean> items = claimList;
List<Trip> tripList = TripBO.getIncompleteTripsList(user);
items.addAll(tripList); // ** Compilter error here **
ClaimBO.getIncompleteClaimsList(user) definition:
public static List<Claim> getIncompleteClaimsList(User user)
Claim definition:
public interface Claim extends Bean, Cloneable
TripBO.getIncompleteTripsList(user) definition:
public static List<Trip> getIncompleteTripsList(User user)
Trip definition:
public interface Trip extends Bean, Cloneable
Compiler error: "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<Trip>)"
Any ideas?
TIA - Adam
> I can't tell for sure why this does not work. The provided information
> is hard to interpret. Please send some source code. What I would think
> can work, though, is if you make MyTypeA and MyTypeB subclasses of a
> common superclass implementing the required interface. You would then
> have a collection of instances of this superclass. Did you consider that
> option? It seems to be a classical case of inheritance.
He did make those types both subtypes of a common supertype already.
The problem is that ? extends Foo allows getting from the collection but not
adding to it, for reasons explained in
<http://java.sun.com/docs/books/tutorial/extra/generics/morefun.html>
and elsewhere.

Signature
Lew
Hendrik Maryns - 25 Oct 2007 15:39 GMT
Lew schreef:
>> I can't tell for sure why this does not work. The provided information
>> is hard to interpret. Please send some source code. What I would think
[quoted text clipped - 9 lines]
> <http://java.sun.com/docs/books/tutorial/extra/generics/morefun.html>
> and elsewhere.
So the solution is to copy over the list when you get it:
List<MyType> list = new ArrayList<MyType>(getMyTypeAList());
List.addAll(getMyTypeBList());
H.

Signature
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Adam Lipscombe - 25 Oct 2007 16:16 GMT
> Lew schreef:
>>> I can't tell for sure why this does not work. The provided information
[quoted text clipped - 16 lines]
>
> H.
Very cool - works a treat.
Thanks!
Adam Lipscombe - 25 Oct 2007 15:56 GMT
OK thanks,
How do I addd to the collection?
TIA - Adam
>> I can't tell for sure why this does not work. The provided information
>> is hard to interpret. Please send some source code. What I would think
[quoted text clipped - 9 lines]
> <http://java.sun.com/docs/books/tutorial/extra/generics/morefun.html>
> and elsewhere.
Lew - 25 Oct 2007 16:08 GMT
> OK thanks,
>
> How do I addd to the collection?
Please do not top-post. Review the FAQ post that appears here every few days,
and the links to which it points.
One way is to drop the wildcard altogether.
Given Foo and Bar both implementing Super:
List <Super> items = getFoos(); // would have to return List <Super>
items.addAll( getBars() );

Signature
Lew
Adam Lipscombe - 25 Oct 2007 16:15 GMT
>> OK thanks,
>>
[quoted text clipped - 9 lines]
> List <Super> items = getFoos(); // would have to return List <Super>
> items.addAll( getBars() );
OK thanks.