title: Java: Using void with Function<T,R> and Consumer<T>
body: <p>Is it possible to invoke Function and Consumer where there are no input parameters?  I tried using keywords void and Void but they are not doing the trick.</p>
  
  <p>In the following code sample, if I uncomment methodRef2 and methodRef4, I get syntax errors.</p>
  
  <pre><code>import java.util.function.Function;
  import java.util.function.Consumer;
  
  public class StackOverflowExample {
      public static void main(String[] args) {
          Function&lt;Integer, Integer&gt; methodRef1 = StackOverflowExample::inIntegerOutInteger;
          methodRef1.apply(1000);
  
          //      Function&lt;void, Integer&gt; methodRef2 = StackOverflowExample::inVoidOutInteger;
          //      methodRef2.apply();
  
          Consumer&lt;Integer&gt; methodRef3 = StackOverflowExample::inIntegerOutVoid;
          methodRef3.accept(45);
  
          //      Consumer&lt;void&gt; methodRef4 = StackOverflowExample::inVoidOutVoid;
          //      methodRef4.accept();
      }
  
      protected static int inIntegerOutInteger(int i) {
          System.out.println("inIntegerOutInteger invoked with value " + i);
          return i;
      }
  
  
      protected static void inIntegerOutVoid(int i) {
          System.out.println("inIntegerOutVoid invoked with value " + i);
      }
  
  
      protected static int inVoidOutInteger() {
          int retVal = 1000;
          System.out.println("inVoidOutInteger invoked: returning value " + retVal);
          return retVal;
      }
  
  
      protected static void inVoidOutVoid() {
          System.out.println("inVoidOutVoid invoked");
      }
  
  }
  </code></pre>