<分区>
假设我有
class Dog extends Animal {}
class Cat extends Animal {}
我有一份动物 list 使用 Guava FluentIterable 我可以一步过滤和转换
List<Cat> cats = FluentIterable.from(animals)
.filter(Cat.class)
.toList();
使用Java8我需要做
List<Cat> cats = animals.stream()
.filter(c -> c instanceof Cat)
.map(c -> (Cat) c)
.collect(Collectors.toList());
我不可能一步完成过滤器和 map ,对吧?