Why is Java's type inference so weak?

后端 未结 3 2130
遇见更好的自我
遇见更好的自我 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 22:05

    Whats harm in doing this?

    Integer i = 42;
    List emptyList = Collections.emptyList();
    Collection result = addToCollection(i, emptyList);
    

    In java 8 it will be taken care.

提交回复
热议问题