public class Reflection extends Object
| Constructor and Description |
|---|
Reflection() |
| Modifier and Type | Method and Description |
|---|---|
static MethodHandle |
defaultInvoker(Method method)
Returns a method handle that invoke a default method of an interface.
|
static <T> Method |
implementation(T instance,
Class<T> base,
String methodName)
Find that method of a given instance that implements the specified abstract method of a given base class.
|
static Object |
invoke(MethodHandle method,
Object target)
Invoke the given method handle with the specified single argument.
|
static <T> T |
lambda(MethodHandles.Lookup caller,
Class<T> type,
MethodHandle target,
TypedArgument... arguments)
Implement a functional interface by a
MethodHandle in the same way that a lambda would. |
static Class<?> |
lambdaClass(Serializable lambda)
Get the class where the method of a (serializable) lambda is implemented.
|
static String |
lambdaImplMethodName(Serializable lambda)
Get the name of the method used to implement a (serializable) lambda.
|
static String |
lambdaParameterName(Serializable lambda)
Get the parameter name of a (serializable) lambda with a single parameter.
|
static MethodHandle |
methodHandle(MethodHandles.Lookup lookup,
Serializable lambda)
Get a method handle to the underlying method that implements a given (serializable)
lambda.
|
static String |
pathOf(Class<?> cls)
Get the location in the classpath from where the given class is loaded.
|
public static String lambdaParameterName(Serializable lambda)
Getting the parameter requires the source to be compiled with the -parameters flag passed to javac and JDK 1.8.0_60 or newer.
lambda - the (serializable) lambda to get the parameter name from.public static <T> T lambda(MethodHandles.Lookup caller, Class<T> type, MethodHandle target, TypedArgument... arguments)
MethodHandle in the same way that a lambda would.T - the type of the functional interface.caller - the lookup context of the caller.type - the functional interface to implement.target - the method handle to implement the method of the functional interface.arguments - extra arguments to be passed to the target method handle, in addition to the arguments of the
implemented method.public static MethodHandle defaultInvoker(Method method)
method - the (default) method to get a method handle for.public static Object invoke(MethodHandle method, Object target)
method - the method handle to invoke.target - the argument to pass to the method.public static Class<?> lambdaClass(Serializable lambda)
lambda - the (serializable) lambda to get the implementing class of.public static String pathOf(Class<?> cls)
cls - the class to find the classpath location of.public static String lambdaImplMethodName(Serializable lambda)
lambda - the lambda to get the implementing method name of.public static MethodHandle methodHandle(MethodHandles.Lookup lookup, Serializable lambda)
lookup - a context that has access to looking up the target method.lambda - the (serializable) lambda to find the implementing method of.public static <T> Method implementation(T instance, Class<T> base, String methodName)
This is useful for finding the actual type that implements a type parameter of the base class.
T - the base type of the instance (the type of the base class).instance - the instance to find the implementation method of.base - the base class that declares the abstract method in question.methodName - the name of the abstract method.Copyright © 2019. All rights reserved.