- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Interface for executing code that returns a value.
An ExceptionedCallableReturns object can be constructed inside an
object's methods so that otherwise hidden fields and methods are
accessible. For example:
Map<String, ExceptionedCallableReturns<Integer>> table = ...;
void foo(final int i) {
CallableReturns<Integer> callable
= new ExceptionedCallableReturns<Integer>() {
public Integer call() throws Exception {
if (i < 0) throw new Exception("negative value");
return Integer.valueOf(i);
}
};
table.put("foo", callable);
}
void bar() {
try {
System.out.println(table.get("foo").call());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
-
Method Summary
-
Method Details
-
call
The method to call.- Returns:
- an object of type T providing the results of the call
- Throws:
Exception
- an exception occurred
-