Lower bounded wildcard not checked against upper bounded type parameter

前端 未结 4 2345
耶瑟儿~
耶瑟儿~ 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:11

    This compiler behavior was discussed on this Eclipse bug. Originally, the Eclipse compiler did error for the expression in your example, while javac did not. Although I haven't yet searched the JLS directly, the consensus seems to be that there is nothing in the spec requiring lower bounded wildcards to be checked against type parameter bounds. In this situation it's ultimately left to the caller to assign a type that satisfies the constraints (as surmised by Stephan Herrmann on that post).

提交回复
热议问题