Java 8 extending stream

后端 未结 3 1989
慢半拍i
慢半拍i 2021-02-15 17:24

I\'m attempting to extend Java 8\'s Stream implementation.

I have this interface:

public interface StreamStuff extends Stream {

    St         


        
3条回答
  •  旧巷少年郎
    2021-02-15 17:49

    You are calling stream() on the Arrays class, which creates its own Stream implementation without any connection to yours. You'd have to produce the Stream yourself, or wrap a stream you obtained elsewhere, in order for something like this to work. Something like this:

    int[] filtered = new StreamStuff(Arrays.stream(arr)).biggerThanFour().toArray();
    

    However, in your case, why don't you just filter?

    int[] filtered = Arrays.stream(arr).filter(i -> i > 4).toArray();
    

提交回复
热议问题