Why is Collection not simply treated as Collection<?>

后端 未结 4 1636
猫巷女王i
猫巷女王i 2021-01-01 09:03

Consider the following API method taken from Shiro\'s org.apache.shiro.subject.PrincipalCollection interface but probably present in other libraries as well:



        
4条回答
  •  时光取名叫无心
    2021-01-01 09:26

    A Collection screams:

    Please don't add anything to me. I have a strict content type, ... well uh, I just forgot what type it is.

    While a Collection says:

    It's all cool ! You can add whatever you like, I have no restrictions.

    So, why shouldn't the compiler translate Collection to Collection ? Because it would put up a lot of restrictions.

提交回复
热议问题