FileVisitor / Are we feature frozen yet?

Ben Evans benjamin.john.evans at gmail.com
Tue Aug 6 13:39:53 UTC 2013


Hi,

I have a suggestion for a point lambdafication change which I don't think
anyone's proposed yet. (As usual, if my Google-fu has failed me, please
point me at the relevant discussion).

In java.nio.file we have the FileVisitor interface, which defines 4 methods.

We also have the SimpleFileVisitor class which defines sane (basically
no-op) implementations of all the methods.

In using FileVisitor, I've noticed that visitFile() tends to be overridden
/ used far more often than the others. It would be nifty if it we could
lambdify in such a way that a lambda expression could be fed to
Files.walkFileTree().

Could we add default implementations to FileVisitor (those from
SimpleFileVisitor seem reasonable) for all methods except visitFile() ?

This would then make code like this possible:

Path homeDir = Paths.get("/Users/kittylyst");
Files.walkFileTree(homeDir, (p, attrs) -> {
System.out.println(p.getFileName()); return FileVisitResult.CONTINUE; });

I have a patch which demonstrates this - let me know if there's potential
here, and if anyone would be interested in sponsoring the patch.

Thanks,

Ben



More information about the core-libs-dev mailing list