Lower bounded wildcard not checked against upper bounded type parameter

前端 未结 4 2351
耶瑟儿~
耶瑟儿~ 2021-02-20 03:01

I wonder why does this piece of code compile successfully?

Source code:

abstract class A
{
    public abstract  A

        
4条回答
  •  离开以前
    2021-02-20 03:33

    There are two parts to your question:

    Part 1: What is the ?

    The presence of a generic parameter on a method makes it a "typed method", which means the method has a generic type that is determined by the caller, usually by inference. It may be bounded. If the class has a type too and the method is an instance method, the two types are unrelated.

    Part 2:

    The generic types must match exactly. The reason boils down to the fact that if B is a subtype of A, SomeClass is not a subtype of SomeClass, more particularly, SomeClass is not a subtype of SomeClass.

提交回复
热议问题