Llamar a un método sobre el valor de retorno de una referencia de método
Tengo una secuencia de archivos que quiero filtrar según el final del nombre del archivo:
public Stream<File> getFiles(String ending) throws IOException {
return Files.walk(this.path)
.filter(Files::isRegularFile)
.map(Path::toFile)
.filter(file -> file.getName().endsWith(ending));
}
Si bien la lambda en la última línea no está mal, pensé que también podría usar referencias de métodos allí, así:
.filter(File::getName.endsWith(ending));
O alternativamente envuelto entre paréntesis. Sin embargo, esto falla conThe target type of this expression must be a functional interface
¿Puedes explicar por qué esto no funciona?