title: How pass methods as parameters in Java using method reference notation (Class::method)?
body: <p>I want to create method in a <code>Utils</code> class that accepts two parameters, the first is the domain class, and the second is a method from the domain class (passed as reference). This <code>Utils</code>' class has a method that will create an instance of the class and execute the method in the scope of the domain class instance.</p>
  <p>For example, the domain class:</p>
  <pre class="lang-java prettyprint-override"><code>public class DomainClass {
    
    public void dummyMethod() {}
    
  }
  </code></pre>
  <p>The Utils class:</p>
  <pre class="lang-java prettyprint-override"><code>public class Utils {
  
    public static void execute(Class&lt;?&gt; clazz, Runnable referenceMethod) {
       Object objInstance = clazz.getConstructor().newInstance();
       // execute the 'referenceMethod' on the scope of 'objInstance'
    }
  
  }
  </code></pre>
  <p>The call I want is something like: <code>Utils.execute(DomainClass.class, DomainClass::dummyMethod)</code>. However, this scenario has some problems:</p>
  <ol>
  <li>How can I pass this parameters for the <code>Utils</code>class (now I'm having some compilation problems)?</li>
  <li>How can I call the 'referenceMethod' with the scope of 'objInstance'?</li>
  </ol>