Point lambdafications in java.io

Joe Darcy joe.darcy at oracle.com
Tue Jun 18 09:46:02 PDT 2013


Hello,

Note that the definition of CloseableStream

public interface CloseableStream<T> extends Stream<T>, AutoCloseable {
     void close();
}

also has the effect of declaring the close method doesn't throw any 
exceptions. The close in AutoCloseable is declared to throw Exception, 
but specializations can and do narrow this.

One idea we had during Project Coin was to add "SilentCloseable" and 
"IdempotentCloseable" subtypes to the platform to to capture "close 
doesn't throw exceptions" and "okay to call close multiple times", 
respectively. However, in the end, we didn't add those types in JDK 7.

Cheers,

-Joe

On 6/18/2013 9:05 AM, Brian Goetz wrote:
> The libraries team added the following methods to java.io and 
> java.nio, with discussion on corelibs-dev:
>
> In java.io.BufferedReader:
>   Stream<String> lines()
>
> In java.nio.Files, static methods for:
>
>   CloseableStream<Path> list(Path dir) throws IOException;
>
>   CloseableStream<Path> walk(Path start, int maxDepth, 
> FileVisitOption... options) throws IOException
>
>   CloseableStream<Path> walk(Path start, FileVisitOption... options) 
> throws IOException
>
>   CloseableStream<Path> find(Path start,
>                            int maxDepth,
>                            BiPredicate<Path, BasicFileAttributes> 
> matcher,
>                            FileVisitOption... options)
>         throws IOException
>
>   CloseableStream<String> lines(Path path, Charset cs) throws IOException
>
>
> CloseableStream simply extends Stream and AutoCloseable, making it 
> suitable for use with try-with-resources:
>
> public interface CloseableStream<T> extends Stream<T>, AutoCloseable {
>     void close();
> }
>
> Should we consider moving AutoCloseable up to Stream and friends, and 
> get rid of CloseableStream?
>



More information about the lambda-libs-spec-experts mailing list