Using the Java 8 Stream API, I would like to register a \"completion hook\", along the lines of:
Stream stream = Stream.of(\"a\",
Check out these complete implementations of AutoClosingReferenceStream, AutoClosingIntStream, AutoClosingLongStream and AutoClosingDoubleStream at the open-source project Speedment https://github.com/speedment/speedment/tree/master/src/main/java/com/speedment/internal/core/stream/autoclose
The solution is similar to the one mentioned by @LukasEder