SingletonIntStream implements IntStream { @Override public void forEach(IntConsumer action) { checkConsumed(); requireNonNull(action); action.accept(element); } private  SingletonIntStream(int element); static IntStream of(int element); @Override IntStream filter(IntPredicate predicate); @Override IntStream map(IntUnaryOperator mapper); @Override Stream<U> mapToObj(IntFunction<? extends U> mapper); @Override LongStream mapToLong(IntToLongFunction mapper); @Override DoubleStream mapToDouble(IntToDoubleFunction mapper); @Override IntStream flatMap(IntFunction<? extends IntStream> mapper); @Override IntStream distinct(); @Override IntStream sorted(); @Override IntStream peek(IntConsumer action); @Override IntStream limit(long maxSize); @Override IntStream skip(long n); @Override void forEach(IntConsumer action); @Override void forEachOrdered(IntConsumer action); @Override int[] toArray(); @Override int reduce(int identity, IntBinaryOperator op); @Override OptionalInt reduce(IntBinaryOperator op); @Override R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R, R> combiner); @Override int sum(); @Override OptionalInt min(); @Override OptionalInt max(); @Override long count(); @Override OptionalDouble average(); @Override IntSummaryStatistics summaryStatistics(); @Override boolean anyMatch(IntPredicate predicate); @Override boolean allMatch(IntPredicate predicate); @Override boolean noneMatch(IntPredicate predicate); @Override OptionalInt findFirst(); @Override OptionalInt findAny(); @Override LongStream asLongStream(); @Override DoubleStream asDoubleStream(); @Override Stream<Integer> boxed(); @Override IntStream sequential(); @Override IntStream parallel(); @Override PrimitiveIterator.OfInt iterator(); @Override Spliterator.OfInt spliterator(); @Override boolean isParallel(); @Override IntStream unordered(); @Override IntStream onClose(Runnable closeHandler); @Override void close(); IntStream takeWhile(IntPredicate predicate); IntStream dropWhile(IntPredicate predicate);  }
@Test void forEach() { instance.forEach(i -> cnt.incrementAndGet()); assertEquals(1, cnt.get()); assertThrows(IllegalStateException.class, () -> instance.forEach(x -> {})); }