Once again problems with wildcards/generic methods
- From: Hendrik Maryns <hendrik_maryns@xxxxxxxxxxxxx>
- Date: Mon, 27 Feb 2006 13:28:31 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
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...
Thanks, H.
--
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
iD8DBQFEAvBve+7xMGD3itQRAtKbAJ9LndQNzjU5xU2G6mrO59KiLEFiAwCaAzOd
eleelq3y0WRZgU1sdBOSo9E=
=fwXP
-----END PGP SIGNATURE-----
.
- Follow-Ups:
- Re: Once again problems with wildcards/generic methods
- From: Roedy Green
- Re: Once again problems with wildcards/generic methods
- From: Hendrik Maryns
- Re: Once again problems with wildcards/generic methods
- Prev by Date: Re: Not sure why runs but does not display I think my thread
- Next by Date: Re: Once again problems with wildcards/generic methods
- Previous by thread: Java Component Scheduling
- Next by thread: Re: Once again problems with wildcards/generic methods
- Index(es):
Relevant Pages
|
|