Is there an interface in Java similar to the Callable interface, that can accept an argument to its call method?
Like so:
public interface MyCallable<V> {
V call(String s) throws Exception;
}
I would rather avoid creating a new type if there already exists something that I can use. Or is there a better strategy to having multiple clients implement and plug in a callable routine?
Copied from here http://www.programmingforums.org/thread27905.html
Since Java 8 there is a whole set of Function-like interfaces in the
java.util.functionpackage. The one you’re asking for specifically is simplyFunction.Prior to Java 8, there was no general-purpose, built-in interface for this, but some libraries provided it.
For example Guava has the
Function<F,T>interface with the methodT apply(F input). It also makes heavy use of that interface in several places.