title: Java. Reference to method without parameters
body: <p>I have one problem in understanding of Java 8 associated with reference to methods as a parameter to static methods. There is my code where I can't find how to send a reference to a method which doesn't have any parameters and must be a method for an object of the definite class.</p>
  
  <p>So, I want that the method which I send to static function may be used for the object in the static method. </p>
  
  <pre><code>import java.io.IOException;
  import java.nio.file.Files;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.util.stream.Stream;
  
  interface FuncForPath&lt;T&gt; {
      T func(T path);
  }
  
  class MethodsForFolder {
  
      public static void printFilesInFolder(Path path, FuncForPath&lt;Path&gt; funcPath) {
          Stream&lt;Path&gt; paths = null;
          try {
              paths = Files.list(path);
          } catch (IOException e) {
              System.out.println(
                      "The problems have been appeared during reading folder: " + path.toAbsolutePath().toString());
              e.printStackTrace();
          }
          System.out.println("Files list in folder:" + path.toAbsolutePath().toString());
          paths.forEach(p -&gt; funcPath.func(p).toString()); // I don't know to how to write this code to perform
      }
  }
  
  public class TestRefToIntance {
  
      public static String testWindowsFloder = "C://Logs";
  
      public static void main(String[] args) {
  
          Path path = Paths.get(testWindowsFloder);
          // I want that this 2 methods are performed depending on transfered methods
          // reference
          MethodsForFolder.printFilesInFolder(path, Path::toAbsolutePath);
          MethodsForFolder.printFilesInFolder(path, Path::getFileName);
      }
  }
  </code></pre>