No Solution? (Was: Once again problems with wildcards/generic methods)
- From: Hendrik Maryns <hendrik_maryns@xxxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 13:54:10 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
Is there no Knowledgeable Person (TM), that can give me a hand here?
Please, I?ve been reading FAQs about generics for some hours now, and
did not find anything helpful (yet).
TIA, H.
Hi,
I have successfully applied generics a few times now, but once again, it
gets a bit more complicated, and Eclipse?s error messages are a bit too
cryptic.
So I have this method
public <T extends State> List<Set<List<T>>> arrangeStates(Set<T> states)
Here, I need the parameter T, because I want to be able to give subtypes
of State to the method, and get a result with the same subtypes (as in
Sun?s Generics Tutorial: parametrised methods should be used if you want
to express a relation between the types of the arguments and/or return
type.) I had to introduce the T, because I want to invoke the method
with a subtype of State (worked fine with State before).
Now another method,
public List<Set<FunctionInputTuple>> sortForArities(Set<? extends State>
states)
invokes arrangeStates like so:
List<Set<List<State>>> arrangedStates = this.arrangeStates(states);
and then goes on doing stuff with it. Here, I did not use a type
parameter, as wildcards are sufficient. But as the knowledgeable will
have noticed, the above line does not compile. How can I change it such
that I can invoke arrangeStates on Set<? extends State>?
The compiler message is this:
Error Type mismatch: cannot convert from List<Set<List<capture-of ?
extends State>>> to List<Set<List<State>>> Signature.java
Eclipse?s Quick Fix proposes to change the type of arrangedStates to
List<Set<List<? extends State>>>, but that gives another warning, and
its suggestions stay the same...
I should add to this that I do not need arrangedStates to be anything
more specific than a list of sets of lists of states (indeed, this is
something cartesian-product like). Whether they are a subtype of states
is not important.
H.
--
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEBEfye+7xMGD3itQRAkzDAJ4kYN3MuDxVQUhqFgcJlKf5w+EOAwCffd20
s1NSm6MYGk5bPbhmw/VChM0=
=xR30
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: No Solution? (Was: Once again problems with wildcards/generic methods)
- From: Bart Cremers
- Re: No Solution? (Was: Once again problems with wildcards/generic methods)
- References:
- Once again problems with wildcards/generic methods
- From: Hendrik Maryns
- Re: Once again problems with wildcards/generic methods
- From: Hendrik Maryns
- Once again problems with wildcards/generic methods
- Prev by Date: Re: Auto Updating an App
- Next by Date: Re: No Solution? (Was: Once again problems with wildcards/generic methods)
- Previous by thread: Re: Once again problems with wildcards/generic methods
- Next by thread: Re: No Solution? (Was: Once again problems with wildcards/generic methods)
- Index(es):
Relevant Pages
|