I am going through an example which pulls an Array of hidden files from current directory related to method reference which is as mentioned below
- using Anonymous inner class implementation
File[] hiddenFiles = new File(".").listFiles(new FileFilter() {
public boolean accept(File file) {
return file.isHidden();
}
});
- using Method reference implementation
File[] hiddenFiles = new File(".").listFiles(File::isHidden);
My question is FileFilter interface has only one abstract method (boolean accept(File pathname))
while implementing accept method using method reference how it is valid to using boolean isHidden() in File class which has no parameters. I learnt that we can apply method reference only when parameters match with abstract method but here accept method has a parameter of type File but isHidden has no parameters. Could you please explain how it is valid.