title: How to specify function types for void (not Void) methods in Java8?
body: <p>I'm playing around with Java 8 to find out how functions as first class citizens. I have the following snippet:</p>
  
  <pre><code>package test;
  
  import java.util.*;
  import java.util.function.*;
  
  public class Test {
  
      public static void myForEach(List&lt;Integer&gt; list, Function&lt;Integer, Void&gt; myFunction) {
        list.forEach(functionToBlock(myFunction));
      }
  
      public static void displayInt(Integer i) {
        System.out.println(i);
      }
  
  
      public static void main(String[] args) {
        List&lt;Integer&gt; theList = new ArrayList&lt;&gt;();
        theList.add(1);
        theList.add(2);
        theList.add(3);
        theList.add(4);
        theList.add(5);
        theList.add(6);
        myForEach(theList, Test::displayInt);
      }
  }
  </code></pre>
  
  <p>What I'm trying to do is pass method <code>displayInt</code> to method <code>myForEach</code> using a method reference. To compiler produces the following error:</p>
  
  <pre><code>src/test/Test.java:9: error: cannot find symbol
        list.forEach(functionToBlock(myFunction));
                     ^
    symbol:   method functionToBlock(Function&lt;Integer,Void&gt;)
    location: class Test
  src/test/Test.java:25: error: method myForEach in class Test cannot be applied to given ty
  pes;
        myForEach(theList, Test::displayInt);
        ^
    required: List&lt;Integer&gt;,Function&lt;Integer,Void&gt;
    found: List&lt;Integer&gt;,Test::displayInt
    reason: argument mismatch; bad return type in method reference
        void cannot be converted to Void
  </code></pre>
  
  <p>The compiler complains that <code>void cannot be converted to Void</code>. I don't know how to specify the type of the function interface in the signature of <code>myForEach</code> such that the code compiles. I know I could simply change the return type of <code>displayInt</code> to <code>Void</code> and then return <code>null</code>. However, there may be situations where it's not possible to alter the method I want to pass somewhere else. Is there an easy way to reuse <code>displayInt</code> as it is?</p>