Re: Once again problems with wildcards/generic methods



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

Hendrik Maryns schreef:
-----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...

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)

iD8DBQFEAvF0e+7xMGD3itQRAkkKAJ9T3+JG2Q9lRJpFb6lv/a3wKdEpcQCeMSl3
9u/qmOqz2PvfvQSXrqq7AHw=
=rjT1
-----END PGP SIGNATURE-----
.



Relevant Pages

  • No Solution? (Was: Once again problems with wildcards/generic methods)
    ... You need GnuPG to verify this message ... I have successfully applied generics a few times now, but once again, it ... Here, I need the parameter T, because I want to be able to give subtypes ... invokes arrangeStates like so: ...
    (comp.lang.java.help)
  • Once again problems with wildcards/generic methods
    ... You need GnuPG to verify this message ... I have successfully applied generics a few times now, but once again, it ... Here, I need the parameter T, because I want to be able to give subtypes ... invokes arrangeStates like so: ...
    (comp.lang.java.help)
  • SOLVED! (Once again problems with wildcards/generic methods)
    ... You need GnuPG to verify this message ... Hendrik Maryns schreef: ... I have successfully applied generics a few times now, but once again, it ... parameter, as wildcards are sufficient. ...
    (comp.lang.java.help)
  • Re: Strategy or Iterator?
    ... Hendrik Maryns wrote in message ... You need GnuPG to verify this message ... Roedy Green schreef: ...
    (comp.lang.java.programmer)
  • Re: Need some guidance on using timer
    ... Hendrik Maryns schreef: ... If it is simply running, only a boolean will be set, ... After some fiddling around, I came with a much easier solution, no need ... Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org ...
    (comp.lang.java.help)