Skip to main content

Suggested cleanup for java.util.stream.Stream JDK 8 b106

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
ashf
Offline
Joined: 2013-09-16

1. java.util.stream.BaseStream should extend Iterable - it already requires iterator() method. Consider the following read/write pipe example:
try (final CloseableStream<String> stream = Files.lines(sourcePath, charset)){
Files.write(destPath, stream, charset);
}

2. Clean up java.util.Spliterator interface - for user defined streams developers would need to implement it.
a. Define Enum instead of bit flags in
int characteristics();
and use EnumSet - introduced in 1.5 specifically for this purpose.
Method default boolean hasCharacteristics(int characteristics) would be obsolete.

b. trySplit() should return Optional<Spliterator>, instead of Spliterator. Optional was introduced specifically for this purpose (i.e. to show that operation may return null value) and is used extensively in Stream interface.