Interface ExceptionedCallableReturns<T>

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ExceptionedCallableReturns<T>
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

    Modifier and Type
    Method
    Description
    The method to call.
  • Method Details

    • call

      T call() throws Exception
      The method to call.
      Returns:
      an object of type T providing the results of the call
      Throws:
      Exception - an exception occurred