How to use lambdas in "template" I have an event handling code, something like
void handleEventType1(EventType1 event1) {
    if (someCheck()){
        function1(event);
        postCheckTrue();
    } else {
        function2(event);
        postCheckFalse();
    }
}

void handleEventType2(EventType2 event2) {
    if (someCheck()){
        function3(event);
        postCheckTrue();
    } else {
        function4(event);
        postCheckFalse();
    }
}

I was hoping, I can do something like
handleEvent(event1, Handler::function1, Handler::function2);
handleEvent(event2, Handler::function3, Handler::function4);

that will somehow call functions (1 or 2) or (3 or 4), but I'm somehow not able to solve it to my satisfaction.
First, lets use inheritance. We will inherit the specific event types from the event interface.
interface Event {}

class EventType1 implements Event{}

class EventType2 implements Event{}

Secondly, lets define the type of functions that we will call in the handleEvent() method. In this case it is Consumer&lt;Event&gt;
Now our handleEvent() function will look like this
void handleEvent(Event event, 
                 Consumer&lt;Event&gt; option1, 
                 Consumer&lt;Event&gt; option2) {
   if (someCheck()) {
      option1.accept(event);
   } else {
       option2.accept(event);
   }
}


Now we can call this function and pass instance of event interface and two lambdas or method references
Handler.handleEvent(new EventType1(),
    event -&gt; {
       //do something
    }, 
    event -&gt; {
       //do something else;
    });
}