Interface FunctionalReference.Introspection
-
- Enclosing interface:
- FunctionalReference
public static interface FunctionalReference.Introspection
Introspection of functional reference.WARNING: This interface is "consume only" from perspective of semantic versioning. Do not implement it, use its instances returned from
FunctionalReference.introspect()
. It might change in backward incompatible way for implementors (but not for clients) in minor version changes, for example by adding abstract method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Class<?>
capturingType()
Extracts class in which referenced method was declared.Set<Annotation>
parameterAnnotations(int index)
Returns annotation that was placed on parameter with specified index in implementation method.int
parametersCount()
Returns number of parameters that reference method has.Type
parameterType(int index)
Returns actual type for parameter by its index.Constructor<?>
referencedConstructor()
Extracts referenced constructor if the implementation was a constructor reference.Method
referencedMethod()
Extracts referenced method if the implementation was a method reference.Type
resultType()
Returns actual type returned by implementation method.<T> T
visit(FunctionalReference.Visitor<T> visitor)
Visitor Pattern acceptor method.
-
-
-
Method Detail
-
visit
@CanIgnoreReturnValue <T> T visit(FunctionalReference.Visitor<T> visitor)
Visitor Pattern acceptor method.This method dispatches type of provided reference to visitor, calling single method for each implementation kind.
- Type Parameters:
T
- type of visitor result- Parameters:
visitor
- visitor to dispatch into- Returns:
- whatever visitor call returned
-
capturingType
Class<?> capturingType()
Extracts class in which referenced method was declared.For lambdas, the method is a synthetic and declared in place where lambda was declared.
- Returns:
- declaration class of the method reference
-
resultType
Type resultType()
Returns actual type returned by implementation method.This might be different from function type return type which the reference implements, because implementation has a return-type-substitutable return type (JLS 8.4.5).
- Returns:
- actual return type for implemented method
-
parametersCount
int parametersCount()
Returns number of parameters that reference method has.This method exists for convenience, as it is always equal to the number of formal parameters in functional interface declaration.
- Returns:
- parameter count of referenced method
-
parameterType
Type parameterType(int index)
Returns actual type for parameter by its index.This might be different from function type parameter because as it must have the same erasure, it can have different parameters, if its parameterized type, or it could be a type variable.
- Parameters:
index
- index of parameter to extract, counting from 0- Returns:
- actual parameter type
-
parameterAnnotations
Set<Annotation> parameterAnnotations(int index)
Returns annotation that was placed on parameter with specified index in implementation method.WARNING: due to bug in JDK, this method can return empty set for lambda methods rather than actual annotations.
This method extracts formal parameter annotations that are placed on parameter of implementation method with specified index.
This method behaves differently when this reference was in "bound" mode, as first of the formal parameters in functional interface will be permanently bound to the specified instance. In this case calling this method with 0 will always produce empty set, as annotations cannot be applied on receiver parameter.
- Parameters:
index
- index of parameter to extract, counting from 0- Returns:
- annotations on parameter type
-
referencedMethod
Method referencedMethod() throws IllegalStateException
Extracts referenced method if the implementation was a method reference.Returns reflection of method of this functional reference. This works for modes "static", "instance" and "bound".
- Returns:
- method that is referenced
- Throws:
IllegalStateException
- if mode of this functional reference is not any of method ones
-
referencedConstructor
Constructor<?> referencedConstructor() throws IllegalStateException
Extracts referenced constructor if the implementation was a constructor reference.Returns reflection of constructor of this functional reference. This works for modes "constructor" only.
- Returns:
- constructor that is referenced
- Throws:
IllegalStateException
- if this reference is not to a constructor
-
-