title: Java 8 constructor method references
body: <p>I am reading Java 8 book, and it comes with a sample I reproduce:</p>
  <pre><code>@FunctionalInterface
  public interface Action {
      public void perform();
  }
  </code></pre>
  <p>An Implementor:</p>
  <pre><code>public final class ActionImpl implements Action {
      public ActionImpl() {
          System.out.println(&quot;constructor[ActionIMPL]&quot;);
      }
  
      @Override
      public void perform() {
          System.out.println(&quot;perform method is called..&quot;);
      }    
  }
  </code></pre>
  <p>A caller:</p>
  <pre><code>public final class MethodReferences {
  
      private final Action action;
  
      public MethodReferences(Action action) {
          this.action = action;
      }
  
      public void execute() {
          System.out.println(&quot;execute-&gt;called&quot;);
          action.perform();
          System.out.println(&quot;execute-&gt;exist&quot;);
      }
  
      public static void main(String[] args) {
          MethodReferences clazz = new MethodReferences(new ActionImpl());
          clazz.execute();
      }
  }
  </code></pre>
  <p>If this is called the following is print into the output:</p>
  <pre><code>constructor[ActionIMPL]
  execute-&gt;called
  perform method is called..
  execute-&gt;exist
  </code></pre>
  <p>Everything is all right but if I use method references not <code>perform message</code> method is printed! Why is this, am I missing something?</p>
  <p>If I use this code:</p>
  <pre><code>MethodReferences clazz = new MethodReferences(() -&gt; new ActionImpl());
  clazz.execute();
  </code></pre>
  <p>Or this code:</p>
  <pre><code>final MethodReferences clazz = new MethodReferences(ActionImpl::new);
  </code></pre>
  <p>This is printed:</p>
  <pre><code>execute-&gt;called
  constructor[ActionIMPL]
  execute-&gt;exist
  </code></pre>
  <p>No exception message or anything else is printed. I am using Java 8 1.8.25 64bit.</p>
  <h2>Update</h2>
  <p>For readers that are studying like me, this is the right running code.</p>
  <p>I have created a class the caller.</p>
  <p>Because I need to implement a empty method &quot;perform from the Action functional interface&quot; which I need to pass as parameter to class constructor <code>MethodReference</code> I reference the &quot;constructor of the MethodReferenceCall which is a empty constructor&quot; and I can use it.</p>
  <pre><code>public class MethodReferenceCall {
      public MethodReferenceCall() {
          System.out.println(&quot;MethodReferenceCall class constructor called&quot;);
      }
  
      public static void main(String[] args) {
          MethodReferenceCall clazz = new MethodReferenceCall();
          MethodReferences constructorCaller = new MethodReferences(MethodReferenceCall::new);
          constructorCaller.execute();
      }
  }
  </code></pre>