Interface CtLambda<T>

Type Parameters:
T - created type
All Superinterfaces:
Cloneable, CtBodyHolder, CtCodeElement, CtElement, CtExecutable<T>, CtExpression<T>, CtNamedElement, CtQueryable, CtTypedElement<T>, CtVisitable, FactoryAccessor, Serializable, SourcePositionHolder, TemplateParameter<T>
All Known Implementing Classes:
CtLambdaImpl

public interface CtLambda<T> extends CtExpression<T>, CtExecutable<T>
This code element represents the creation of a lambda. A lambda can have two sorts of body : an simple expression or a block of statements. The usage of this concept in this class is:
     java.util.List l = new java.util.ArrayList();
     l.stream().map(
       x -> { return x.toString(); } // a lambda
     );
 
  • If your lambda has an expression, getBody method will return null and getExpression method will return a CtExpression.
  • If your lambda has a block of statement, getExpression method will return null and getBody will returns a CtBlock with all statements.
So keep this in mind when you would like the body of a CtLambda.
  • Method Details

    • getExpression

      CtExpression<T> getExpression()
      Gets the expression in the body. Null if the body is a list of statements.
    • getOverriddenMethod

      <R> CtMethod<R> getOverriddenMethod()
      Returns:
      the method that this lambda expression implements. Must be defined as a non-default method in an interface, e.g. Consumer.accept().
    • setExpression

      <C extends CtLambda<T>> C setExpression(CtExpression<T> expression)
      Sets the expression in the body of the lambda. Nothing will change if the lambda already has a value in the body attribute.
    • clone

      CtLambda<T> clone()
      Description copied from interface: CtElement
      Clone the element which calls this method in a new object. Note that that references are kept as is, and thus, so if you clone whole classes or methods, some parts of the cloned element (eg executable references) may still point to the initial element. In this case, consider using methods Refactoring.copyType(CtType) and Refactoring.copyMethod(CtMethod) instead which does additional work beyond cloning.
      Specified by:
      clone in interface CtCodeElement
      Specified by:
      clone in interface CtElement
      Specified by:
      clone in interface CtExecutable<T>
      Specified by:
      clone in interface CtExpression<T>
      Specified by:
      clone in interface CtNamedElement
    • setThrownTypes

      <T1 extends CtExecutable<T>> T1 setThrownTypes(Set<CtTypeReference<? extends Throwable>> thrownTypes)
      Description copied from interface: CtExecutable
      Sets the thrown types.
      Specified by:
      setThrownTypes in interface CtExecutable<T>