Interface ExceptionedCallableArgsReturns<T,Args>

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 ExceptionedCallableArgsReturns<T,Args>
Interface for executing code that returns a value and that may raise a checked exception. An ExceptionedCallableArgsReturns object can be constructed inside an object's methods so that otherwise hidden fields and methods are accessible. For example:

  Map<String, ExceptionedCallableArgsReturns<Integer,Integer>>
        table = ...;
  void foo(final int i) {
     CallableArgsReturns<Integer,Integer> callable
       = new ExceptionedCallableArgsReturns<Integer,Integer>() {
                 public Integer call(Integer... args) throws Exception {
                     if (i < 0) throw new Exception("negative value");
                     int j = (args.length == 0)? 0: (args[0]);
                     return Integer.valueOf(i + j);
                 }
             };
     table.put("foo", callable);
 }

 void bar(int j) {
     try {
         System.out.println(table.get("foo").call(Integer.valueOf(j)));
     } catch (Exception e) {
         e.printStackTrace();
         System.exit(1);
     }
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    call(Args... args)
    The method to call.
  • Method Details

    • call

      T call(Args... args) throws Exception
      The method to call.
      Parameters:
      args - additional arguments supplied by the caller when this method is called
      Returns:
      an object of type T providing the results of the call
      Throws:
      Exception - an exception occurred