This is a code snippet that tries to use a functional interface inside the filter function.
Function<Path, Boolean> isNotPartitionFile = (path) -> {
return !path.toString().contains("partition");
};
List<Path> pathsList = Files.walk(Paths.get(extractFilesLocation))
.filter(Files::isRegularFile)
.filter(isNotPartitionFile)
.collect(Collectors.toList());
When I try to use the isNotPartitionFile
as a parameter to the filter()
function, eclipse pops up an error that says The method filter(Predicate<? super Path>) in the type Stream<Path> is not applicable for the arguments (Function<Path,Boolean>)
. It also suggests to cast to (Predicate<? super Path>)
, but this throws a runtime error that says it cannot be casted.
How do I overcome this ?