What is the difference between A and A<? extends B>?

后端 未结 4 1889
借酒劲吻你
借酒劲吻你 2020-12-23 10:57

I am a new java learner. Recently I was reading Generic programming and got my self confused with this...

A and A
         


        
4条回答
  •  长情又很酷
    2020-12-23 11:22

    (a long comment, not an answer)

    Totally different things. The similarity in syntax is a grave mistake made by Java. And this mistake leads to a bigger mistake - many people try to understand wildcard as a type parameter (i.e. wildcard capture)

    There was no such thing as A until Java invented it. Until then the syntax used by researchers was A. Java thought that it is too mysterious for our poor programmers, so it invented that syntax A that seems to read better on first round.

    Well it is damn verbose and ugly. If an API has a few wildcard, it looks like vomit of symbols.

    But the worse thing is the confusion it causes. It looks like a type parameter. And Java did that on purpose! Java did not believe that its programmers can ever understand covariant types, so syntactically it made the convariant types look like parameterized types, to guide programmers into the erroneous way of understanding, that, admittedly, can be useful in occasions, but ultimately makes people clueless.

提交回复
热议问题