2

I was going through the concept of capture conversion from JLS ยง5.1.10, and came across this statement:

Capture conversion is not applied recursively.

Unfortunately there is no example there to explain what it really means, and I'm having hard time understand it. I also went through this post, but that too doesn't go into detail of recursive capture. Can someone explain with some example?

Community
  • 1
  • 1
user3011937
  • 261
  • 1
  • 2
  • 8

1 Answers1

4

Capture conversion is only applied on the 1st level wildcards.

For example, if an object is of type List<? extends X>, we know the object is also a List<T> for some T that is a subtype of X.

However, if an object is of type List<List<?>>, it is not a List<List<T>> for some T.

A List<? extends List<?>> can be capture-converted to List<T> for some T that is subtype of List<?>. However the 2nd ? cannot be eliminated.

ZhongYu
  • 19,446
  • 5
  • 33
  • 61