Why is Java's type inference so weak?

后端 未结 3 2101
遇见更好的自我
遇见更好的自我 2021-01-05 21:27

Say, I have a method:

public static  Collection addToCollection(T element, Collection collection) {
    collection.add(element);
          


        
3条回答
  •  不知归路
    2021-01-05 21:48

    Collections.emptyList() returns a List which is passed through your addToCollection() method. And since Object is not Integer, this fails.

    提交回复
    热议问题