Interface CapturingCreator

All Known Subinterfaces:
AnonymousClassCreator, LambdaCreator

public sealed interface CapturingCreator permits AnonymousClassCreator, LambdaCreator
A creator for an entity which can capture values from an enclosing scope.
  • Method Summary

    Modifier and Type
    Method
    Description
    default Var
    capture(Var outer)
    Capture an enclosing variable so that it may be used in the lambda body.
    capture(String name, Expr value)
    Capture an enclosing value as a variable so that it may be used in the lambda body.
  • Method Details

    • capture

      Var capture(String name, Expr value)
      Capture an enclosing value as a variable so that it may be used in the lambda body. All values that are created outside the lambda must be captured into new variables (even this) in order to be used within the lambda, otherwise a generation-time exception may be thrown.

      If the given expression is a variable, the given name overrides the variable's name within the scope of the lambda.

      Names of captured variables must be unique for each anonymous class / lambda.

      Parameters:
      name - the name of the variable (must not be null)
      value - the capture value (must not be null)
      Returns:
      the captured variable (not null)
    • capture

      default Var capture(Var outer)
      Capture an enclosing variable so that it may be used in the lambda body.

      Name of the variable is used unchanged. Note that names of captured variables must be unique for each anonymous class / lambda.

      Parameters:
      outer - the enclosing variable to capture (must not be null)
      Returns:
      the captured variable (not null)