How to implement a Java stream?

后端 未结 5 880
悲哀的现实
悲哀的现实 2020-12-01 06:34

I want to implement a Stream.

I don\'t want to just use implements Stream, because I would have to implement a ton of met

5条回答
  •  有刺的猬
    2020-12-01 07:00

    Others have answered how to provide a general-purpose Stream implementation. Regarding your specific requirement, just do this:

    class Foo {
    
        T t1, t2, t3;
    
        Foo(T t1, T t2, T t3) {
            this.t1 = t1;
            this.t2 = t2;
            this.t3 = t3;
        }
    
        Stream stream() {
            return Stream.of(t1, t2, t3);
        }
    }
    

提交回复
热议问题