The back of the lambda functions, we will create anonymous classes for implementing interfaces on the fly.
Here is the interface as it is Consumer<MyListener>unavailable:
public interface MyConsumer {
public void accept(MyListener l);
}
Then you can use:
private void handleCanNotConnect(final Throwable cause) {
isConnected = false;
fireAll(new MyConsumer() {
@Override
public void accept(MyListener l) {
l.connectionFailed(cause);
}
});
}
private void fireAll(MyConsumer action){
action.accept(listener);
}
Note that causemarked as final.
source
share