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