Prior to Java 8, this method would be used to create a list of hidden files:
File[] hiddenFiles = new File("./directory/").listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isHidden();
}
});
In Java 8, this can be shortened to:
File[] hiddenFiles = new File("./directory/").listFiles(File::isHidden);
Returning non-hidden files in the original code was a trivial change: return file.!isHidden();
as a substitute for return file.isHidden();
. I cannot recreate this functionality within a single line.
There is no isNotHidden
function within the File class. Without creating one (or without deferring to the original, more verbose code), is there a way to recreate it using the new single-line style?