So,whatconcretetype(subclass ) of List is being used here? Are there any guarantees?
查看Collectors#toList ()文档时,“不能保证返回的List的类型、偏差、可序列化性或线程安全。 若要返回特定实现,请改为使用collectors # to collection (supplier )。
Supplier supplier=() -新链接列表);
List blue=shapes.stream (
. filter(s-s.getcolor ) (==BLUE ) ) ) ) ) ) )。
. collect (collectors.to collection ) supplier );
可以从lambda返回到您想要的List Shape实现。
更新:
或者,也可以用方法引用:
List blue=shapes.stream (
. filter(s-s.getcolor ) (==BLUE ) ) ) ) ) ) )。
. collect (collectors.to collection )链接列表3360: new );