Java Map compiler error with generic

前端 未结 6 2265
孤独总比滥情好
孤独总比滥情好 2020-12-19 23:31
// I know that this method will generated duplicate 
// trim keys for the same value but I am just
// trying to understand why we have a compile error:
// The method         


        
6条回答
  •  情歌与酒
    2020-12-19 23:41

    ? is not a wildcard for any type but the unknown type. So the map only accepts ?-type objects and not String. One conclusion from this (rather strange) fact: We can't add values to collections that are parametized with ?.

提交回复
热议问题