• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Wilcard capture conversion? (Tough question)

 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ranchers.

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 ]
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What is X and what is Y?


The quote you give explains what X and Y are:

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.

Layne
[ January 19, 2006: Message edited by: Layne Lund ]
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!