Is there a simple Interface in Java like the following code?
public interface Delegate {
void action();
}
Java Delegates? describes the functionality well. It's not a Supplier, not a Consumer, not a Function, not a Runnable(no async stuff needed), I just want to pass a lambda to a method to be executed in between common parts.
Now I'm wondering why I have to define this interface myself. Am I just unable to find the standard Java interface for this or am I missing some vital drawback here?
Usage in my code (simplified):
public void transferX(Xrequest request){
transfer(request, () -> this.typedWrite(request));
}
public void transferY(Yrequest request){
transfer(request, () -> this.typedWrite(request));
}
void transfer(BaseRequest request, final Delegate writeFunction){
...
try{
writeFunction.action();
...
catch(...){...}
}
void typedWrite(Xrequest request){...}
void typedWrite(Yrequest request){...}