How to cast List<Object> to List

后端 未结 16 918
时光取名叫无心
时光取名叫无心 2020-11-27 11:43

This does not compile, any suggestion appreciated.

 ...
  List list = getList();
  return (List) list;


Compil

16条回答
  •  时光取名叫无心
    2020-11-27 12:13

    Another approach would be using a java 8 stream.

        List customer = myObjects.stream()
                                      .filter(Customer.class::isInstance)
                                      .map(Customer.class::cast)
                                      .collect(toList());
    

提交回复
热议问题