Interface MethodReferenceExpression
- All Superinterfaces:
ExpressionDef
MyClass::staticMethod.
It implements the same functional interface a ExpressionDef.Lambda does, but instead of a
generated body it points directly at an existing method. Each form is its own type:
StaticMethodReferenceExpression, InstanceMethodReferenceExpression and ConstructorMethodReferenceExpression.
Only a reference that needs no further input is an expression - an instance method becomes one once bound to a receiver.
Create one from the LambdaDef of the interface being implemented, or with
ClassTypeDef.staticMethodReference(ClassTypeDef, MethodDef), ClassTypeDef.constructorReference(ClassTypeDef, MethodDef) and
ClassTypeDef.methodReference(ExpressionDef, MethodDef).
- Since:
- 2.2
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested classes/interfaces inherited from interface ExpressionDef
ExpressionDef.And, ExpressionDef.ArrayElement, ExpressionDef.Cast, ExpressionDef.ComparisonOperation, ExpressionDef.ConditionExpressionDef, ExpressionDef.Constant, ExpressionDef.EqualsReferentially, ExpressionDef.EqualsStructurally, ExpressionDef.GetPropertyValue, ExpressionDef.IfElse, ExpressionDef.InstanceOf, ExpressionDef.InvokeGetClassMethod, ExpressionDef.InvokeHashCodeMethod, ExpressionDef.InvokeInstanceMethod, ExpressionDef.InvokeStaticMethod, ExpressionDef.IsFalse, ExpressionDef.IsNotNull, ExpressionDef.IsNull, ExpressionDef.IsTrue, ExpressionDef.Lambda, ExpressionDef.MathBinaryOperation, ExpressionDef.MathUnaryOperation, ExpressionDef.NewArrayInitialized, ExpressionDef.NewArrayOfSize, ExpressionDef.NewInstance, ExpressionDef.NotEqualsReferentially, ExpressionDef.NotEqualsStructurally, ExpressionDef.Or, ExpressionDef.StringConcatenation, ExpressionDef.Switch, ExpressionDef.SwitchYieldCase -
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable ExpressionDefinstance()The receiver a reference bound to an instance captures.Returns the interface method with the type variables of the interface resolved.invoke(ExpressionDef... expressions) Invoke the method reference.invoke(List<? extends ExpressionDef> expressions) Invoke the method reference.default booleanWhether the referenced method is a constructor.default booleanisStatic()Whether the referenced method is called statically.method()Returns the method this reference points at.default Stream<? extends ExpressionDef> Stream of nested expressions included in this expression.static MethodReferenceExpressionof(ClassTypeDef functionalInterface, Constructor<?> constructor) Implement the interface with a reference to a constructor, e.g.static MethodReferenceExpressionof(ClassTypeDef functionalInterface, Method method) Implement the interface with a reference to a static method, e.g.owner()Returns the type the referenced method is declared on.target()Returns the method the interface declares, erased as the interface declares it.type()Returns the functional interface being implemented.Methods inherited from interface ExpressionDef
arrayElement, arrayElement, asExpressionSwitch, asStatementSwitch, asStatementSwitch, cast, cast, compare, doThrow, equalsReferentially, equalsStructurally, field, field, field, getPropertyValue, ifFalse, ifFalse, ifFalse, ifNonNull, ifNonNull, ifNonNull, ifNull, ifNull, ifNull, ifTrue, ifTrue, ifTrue, instanceOf, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invoke, invokeConstructor, invokeConstructor, invokeConstructor, invokeConstructor, invokeConstructor, invokeConstructor, invokeConstructor, invokeConstructor, invokeGetClass, invokeHashCode, isFalse, isNonNull, isNull, isTrue, math, math, newLocal, newLocal, notEqualsReferentially, notEqualsStructurally, returning, stringConcat, whileLoop
-
Method Details
-
of
Implement the interface with a reference to a static method, e.g.MyClass::staticMethod.- Parameters:
functionalInterface- The interface the reference implementsmethod- The referenced static method- Returns:
- the method reference expression
- Since:
- 2.2
-
of
Implement the interface with a reference to a constructor, e.g.MyClass::new.- Parameters:
functionalInterface- The interface the reference implementsconstructor- The referenced constructor- Returns:
- the method reference expression
- Since:
- 2.2
-
type
ClassTypeDef type()Returns the functional interface being implemented.- Specified by:
typein interfaceExpressionDef- Returns:
- The type of the functional interface, e.g.
Function<String, String>
-
isStatic
default boolean isStatic()Whether the referenced method is called statically.The implementations are not visible outside the model, so the forms are told apart with this,
isConstructor()andinstance()rather than by type.- Returns:
- True if this is a reference to a static method
-
isConstructor
default boolean isConstructor()Whether the referenced method is a constructor.- Returns:
- True if this is a reference to a constructor
-
instance
The receiver a reference bound to an instance captures.- Returns:
- The receiver, or
nullwhen the reference is not bound to one
-
target
-
instantiated
MethodDef instantiated()Returns the interface method with the type variables of the interface resolved.- Returns:
- The interface method with its type variables resolved, e.g.
String apply(String)
-
owner
ClassTypeDef owner()Returns the type the referenced method is declared on.- Returns:
- The type declaring the referenced method
-
method
-
invoke
Invoke the method reference.- Parameters:
expressions- The expressions- Returns:
- The method invocation
-
invoke
Invoke the method reference.- Parameters:
expressions- The expressions- Returns:
- The method invocation
-
nestedExpressionsStream
Description copied from interface:ExpressionDefStream of nested expressions included in this expression.- Specified by:
nestedExpressionsStreamin interfaceExpressionDef- Returns:
- The expressions
-