Understanding the use of generics in java

后端 未结 3 1915
情深已故
情深已故 2021-01-03 00:06

Im trying to understand how class generics work and this bit just doesnt make sense to me.

So for instance if I have the following classes:

class A&l         


        
3条回答
  •  孤城傲影
    2021-01-03 00:52

    The error message is: The method go(capture#1-of ? extends A) in the type A is not applicable for the arguments (A)

    The reason for it: You are not specific about reference a1. It is defined on a capture of "? extends A" that can never be duplicated. Again, when you create a new A() it passes another capture of the "? extends A", the A itself, that cannot be converted to the former.

提交回复
热议问题