Why does this java 8 stream operation evaluate to Object instead of List<Object> or just List?

后端 未结 2 1553
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 12:32

I\'m working with a 3d party library, and they return Collections that lack type specifications (e.g. public List getFoo();) , and I\'m trying to convert their

2条回答
  •  暖寄归人
    2020-11-28 13:23

    Collectors.toList() returns a List, not an ArrayList. This will compile:

    public static void main(String[] args) {
        ArrayList l = getRawArrayList();
        List l2 = l.stream().map(Object::toString).collect(Collectors.toList());
    
    }
    

提交回复
热议问题