I'm doing some research on Java NIO.2 and its file operations, and currently I'm playing with filetree-walking functions and classes.
NIO.2 FileVisitor
API is wonderful, it's a shame that such thing has been added to Java SE only recently, not ten years ago. However, there is something which slightly bothers me: what is the point of making FileVisitor
interface generic?
Every single example on the net shows how to use it with Files.walkFileTree()
which implies that we are using FileVisitor<Path>
type. But I just cannot see any use for this interface for things other than Path
. Well, it may be possible to use FileVisitor
to walk other kinds of trees (in-memory ones?), but this just doesn't feel right: this interface and related classes have very specific names semantically tied to files, and also FileVisitor
's methods throw IOException
s.
So, were there any reasons for parameterizing FileVisitor
type?