I am learning File Handling in
java and came across the File class.
Statement:
The File class has a method called list().
One of the overloaded methods called list takes in FilenameFilter Reference Object.
The interface FilenameFilter has a method called accept, with the signature - > boolean accept(File dir,
String name).
Question:
Since accept is an instance method called (indirectly, through FilenameFilter reference) by a File object, what is the use of File object calling a method and passing itself to a method? I see no obvious use of how this would help to filter files?
example:
The above code makes no use of File object in the accept method, especially when the File object is the same object which called the method in the first place. Can anyone suggest use or if I am missing any deeper concept. As accept method can do just fine without a File object reference.
Thanks in advance.