I am doing some effort to understand wildcard capture conversion and I would appreciate to validate with you my interpretation of the subject, because it's been tough for me to understand it and I am starting to believe it is one of the most difficult subjects on Generics.
Correct me if I am wrong, please
If I have this generic method....
...I could pass a variable of a concrete type like...
...or a variable with a wildcard, like this:
...in this case, capture conversion is used, defining that the type "T" of the method getMeBack is "capture of ? extends String". Right?
Now, according to the rules of capture conversion, there must be a unique mapping between the capture of the wildcard and the type of the variable involved. Capture conversion won't apply if the type parameter is used with more then one method parameter.
Now, this method:
..with this code (which is no subject to capture conersion) compiles fine:
...but this code, subject to capture conversion, does not:
Now, the Java Programming Language 4th Edition, by James Goslin, Ken Arnold y Davidl Holmes says regarding this affair:
[...] The problem is that the process for resolving the method call will essentially replace the type of the first argument with X, the type of the second argument with Y, and see if T is uniquely determined. But because X is not the same as Y this is not the case.
Now please, can somebody explain me what does this mean??? Because I do not get it. What is X and what is Y?
Thanks in advance, Edwin Dalorzo
[ January 19, 2006: Message edited by: Edwin Dalorzo ] [ January 19, 2006: Message edited by: Edwin Dalorzo ]
replace the type of the first argument with X, the type of the second argument with Y
In other words, the author is using X to stand for the type of the first argument and Y to stand for the type of the second argument. In your Jedi example, the types apparently do not match so you get a compiler error. Although I'm not sure what the concrete types are. This is a guess based on the information you have provided. I am also learning about generics myself, so take it for what it's worth.