How to implement Stream<E> without a resource leak warning in Java
问题 I wish to implement the Stream<E> interface (I admit, it's the unnecessarily large one) and add a builder method foo() . public MyStream<E> implements Stream<E>, ExtendedStream<E> { private final Stream<E> delegate; public MyStream(final Stream<E> stream) { this.delegate = stream; } // a sample Stream<E> method implementation @Override public <R> MyStream<R> map(Function<? super E, ? extends R> mapper) { return new MyStream<>(this.delegate.map(mapper)); } // the rest in the same way (skipped)