title: How to pass a function as method parameter in java when I can not change the original function
body: <p>I have found a lot of answers about this question but all of them says that we have to first change the function definition or create an interface for the function (or similar things)</p>
  <p>My use case is this, I am extending an external <code>Plugin</code> class that has a protected method <code>notifyListeners</code></p>
  <pre class="lang-java prettyprint-override"><code>  /**
     * Notify all listeners that an event occurred
     * This calls {@link Plugin#notifyListeners(String, JSObject, boolean)}
     * with retainUntilConsumed set to false
     * @param eventName
     * @param data
     */
    protected void notifyListeners(String eventName, JSObject data) {
      notifyListeners(eventName, data, false);
    }
  </code></pre>
  <p>I have a function in another class that does some work that for the nature of it, can not return the end value (I can not change this) so I want to take <code>notifyListeners</code> (<code>this:: notifyListeners</code>) as a parameter into that class function but I can not find how to define that. I tried with <code>Function&lt;T, R&gt;</code> but it does not take void as a return parameter.</p>
  <p>Is this possible?</p>