Alex Rivera | Logout

JDK interface for processing a generic parameter

Asked 2011-12-13T01:39:52.137
14

Is there an interface from the JDK that looks something like this:

public interface Callback<T> {
    public void process(T t);
}

The requirement is to implement a callback that runs code, but doesn't return anything.

I could write my own (by simply using the example code here), but I'd like to use an existing wheel if one exists, rather that reinventing one.

Edit
Report

1 Answer

1

I've used Callable ( http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Callable.html) to implement callbacks/functors in java.

interface Callable<V> {
    public V call();
}

You can process this using the Executors stuff in java.util.concurrent.

answered 2011-12-21T16:58:44.680

Your Answer