A simple 1-argument callback interface. Callbacks are typically created as anonymous classes. In order to make debugging easier, it is recommended to override the Object#toString method so that it returns a string that briefly explains what the callback does. If you use {@link Deferred
| 37 | * @param <T> The argument type of the callback. |
| 38 | */ |
| 39 | public interface Callback<R, T> { |
| 40 | |
| 41 | /** |
| 42 | * The callback. |
| 43 | * @param arg The argument to the callback. |
| 44 | * @return The return value of the callback. |
| 45 | * @throws Exception any exception. |
| 46 | */ |
| 47 | public R call(T arg) throws Exception; |
| 48 | |
| 49 | /** The identity function (returns its argument). */ |
| 50 | public static final Callback<Object, Object> PASSTHROUGH = |
| 51 | new Callback<Object, Object>() { |
| 52 | public Object call(final Object arg) { |
| 53 | return arg; |
| 54 | } |
| 55 | public String toString() { |
| 56 | return "passthrough"; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | } |