Interface CallableReturns<T>

All Superinterfaces:
Callable<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 CallableReturns<T> extends Callable<T>
Interface for executing code that returns a value. A CallableReturns object can be constructed inside an object's methods so that otherwise hidden fields and methods are accessible. For example

  Map<String, CallableReturns<Integer>> table = ...;
  void foo(final int i) {
     CallableReturns<Integer> callable
       = new CallableReturns<Integer>() {
                 public Integer call() {
                     return Integer.valueOf(i);
                 }
             };
     table.put("foo", callable);
 }

 void bar() {
     System.out.println(table.get("foo").call());
  }
 
Note: this class was written independently of the class Callable and was subsequently modified to extend Callable for interoperability reasons. It is not being deprecated because the naming convention fits a pattern used in this package.
  • Method Summary

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

    • call

      T call()
      The method to call.
      Specified by:
      call in interface Callable<T>
      Returns:
      an object of type T providing the results of the call