我需要多次使用一个流。我试过这样的事情:
public static void main(String[] args) {
Stream<Integer> stream = Arrays.stream(new Integer[]{1, 2, 3, 4, 5, 6, 7, 8});
Supplier<Stream<Integer>> saved = saveStream(stream.filter(e -> e % 2 == 0));
System.out.println(saved.get().count());
System.out.println(saved.get().max(Integer::compareTo).get());
System.out.println(saved.get().min(Integer::compareTo).get());
}
public static Supplier<Stream<Integer>> saveStream(Stream<Integer> stream){
Supplier<Stream<Integer>> result = new Supplier<Stream<Integer>>() {
@Override
public Stream<Integer> get() {
Stream<Integer> st = stream;
return st;
}
};
return result;
}
但它不起作用...
有什么建议吗?