Package io.microsphere.invoke
Class MethodHandlesLookupUtils
- java.lang.Object
-
- io.microsphere.invoke.MethodHandlesLookupUtils
-
- All Implemented Interfaces:
Utils
public abstract class MethodHandlesLookupUtils extends java.lang.Object implements Utils
Utilities class providing convenient methods for working withMethodHandles.Lookup
.This class offers various static methods to simplify the process of obtaining and using method handles, particularly for public virtual and static methods. It serves as a central utility to reduce boilerplate code when dealing with reflection and method handle lookup.
Example Usage
- Finding a public virtual method:
MethodHandle mh = MethodHandlesLookupUtils.findPublicVirtual(String.class, "toString");
- Finding a public static method:
MethodHandle mh = MethodHandlesLookupUtils.findPublicStatic(Math.class, "abs", int.class);
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
MethodHandles
,MethodHandle
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.invoke.MethodHandle
NOT_FOUND_METHOD_HANDLE
MethodHandle
for Not-Foundstatic java.lang.invoke.MethodHandles.Lookup
PUBLIC_LOOKUP
TheMethodHandles.Lookup
forMethodHandles.publicLookup()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.lang.invoke.MethodHandle
find(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
protected static java.lang.invoke.MethodHandle
find(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.reflect.Method method, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
protected static java.lang.invoke.MethodHandle
findPublic(java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
protected static java.lang.invoke.MethodHandle
findPublic(java.lang.reflect.Method method, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
static java.lang.invoke.MethodHandle
findPublicStatic(java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class... parameterTypes)
The convenient method to findMethodHandles.Lookup.findStatic(Class, String, MethodType)
for public static methodstatic java.lang.invoke.MethodHandle
findPublicVirtual(java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class... parameterTypes)
The convenient method to findMethodHandles.Lookup.findVirtual(Class, String, MethodType)
for public method
-
-
-
Method Detail
-
findPublicVirtual
public static java.lang.invoke.MethodHandle findPublicVirtual(java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class... parameterTypes)
The convenient method to findMethodHandles.Lookup.findVirtual(Class, String, MethodType)
for public method- Parameters:
requestedClass
- the class to be looked upmethodName
- the target method nameparameterTypes
- the types of target method parameters- Returns:
MethodHandle
-
findPublicStatic
public static java.lang.invoke.MethodHandle findPublicStatic(java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class... parameterTypes)
The convenient method to findMethodHandles.Lookup.findStatic(Class, String, MethodType)
for public static method- Parameters:
requestedClass
- the class to be looked upmethodName
- the target method nameparameterTypes
- the types of target method parameters- Returns:
MethodHandle
-
findPublic
protected static java.lang.invoke.MethodHandle findPublic(java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
-
find
protected static java.lang.invoke.MethodHandle find(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.Class<?> requestedClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
-
findPublic
protected static java.lang.invoke.MethodHandle findPublic(java.lang.reflect.Method method, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
-
find
protected static java.lang.invoke.MethodHandle find(java.lang.invoke.MethodHandles.Lookup lookup, java.lang.reflect.Method method, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,java.lang.invoke.MethodType,java.lang.invoke.MethodHandle> function)
-
-