类 MethodHandleUtils


  • public abstract class MethodHandleUtils
    extends BaseUtils
    The utilities class for MethodHandle
    从以下版本开始:
    1.0.0
    作者:
    Mercy
    • 嵌套类概要

      嵌套类 
      修饰符和类型 说明
      static class  MethodHandleUtils.LookupMode
      The allowed MethodHandles.Lookup modes enumeration
    • 字段概要

      字段 
      修饰符和类型 字段 说明
      static int ALL_MODES
      A single-bit mask representing all accesses (public, private, protected and package) The value, 0x0f, happens to be the same as the value of the modifier bit.
      static int MODULE
      A single-bit mask representing module access, which may contribute to the result of lookupModes.
      static java.lang.invoke.MethodHandle NOT_FOUND_METHOD_HANDLE
      MethodHandle for Not-Found
      static int ORIGINAL
      A single-bit mask representing original access which may contribute to the result of lookupModes.
      static int PACKAGE
      A single-bit mask representing package access (default access), which may contribute to the result of lookupModes.
      static int PRIVATE
      A single-bit mask representing private access, which may contribute to the result of lookupModes.
      static int PROTECTED
      A single-bit mask representing protected access, which may contribute to the result of lookupModes.
      static int PUBLIC
      A single-bit mask representing public access, which may contribute to the result of lookupModes.
      static int UNCONDITIONAL
      A single-bit mask representing unconditional access which may contribute to the result of lookupModes.
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      protected static java.lang.invoke.MethodHandle find​(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class[] parameterTypes, ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,​java.lang.invoke.MethodType,​java.lang.invoke.MethodHandle> function)  
      static java.lang.invoke.MethodHandle findStatic​(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class... parameterTypes)
      The convenient method to find MethodHandles.Lookup.findStatic(Class, String, MethodType)
      static java.lang.invoke.MethodHandle findVirtual​(java.lang.Class<?> lookupClass, java.lang.String methodName, java.lang.Class... parameterTypes)
      The convenient method to find MethodHandles.Lookup.findVirtual(Class, String, MethodType)
      static java.lang.invoke.MethodHandles.Lookup lookup​(java.lang.Class<?> lookupClass)
      Create an instance of MethodHandles.Lookup by the specified lookup class with all accesses (public, private, protected and package)
      static java.lang.invoke.MethodHandles.Lookup lookup​(java.lang.Class<?> lookupClass, MethodHandleUtils.LookupMode... lookupModes)
      Create an instance of MethodHandles.Lookup by the specified lookup class with all access (public, private, protected and package)
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 字段详细资料

      • PUBLIC

        public static final int PUBLIC
        A single-bit mask representing public access, which may contribute to the result of lookupModes. The value, 0x01, happens to be the same as the value of the public modifier bit.

        A Lookup with this lookup mode performs cross-module access check with respect to the lookup class and previous lookup class if present.

        另请参阅:
        MethodHandles.Lookup.PUBLIC, 常量字段值
      • PRIVATE

        public static final int PRIVATE
        A single-bit mask representing private access, which may contribute to the result of lookupModes. The value, 0x02, happens to be the same as the value of the private modifier bit.
        另请参阅:
        MethodHandles.Lookup.PRIVATE, 常量字段值
      • PROTECTED

        public static final int PROTECTED
        A single-bit mask representing protected access, which may contribute to the result of lookupModes. The value, 0x04, happens to be the same as the value of the protected modifier bit.
        另请参阅:
        MethodHandles.Lookup.PROTECTED, 常量字段值
      • PACKAGE

        public static final int PACKAGE
        A single-bit mask representing package access (default access), which may contribute to the result of lookupModes. The value is 0x08, which does not correspond meaningfully to any particular modifier bit.
        另请参阅:
        MethodHandles.Lookup.PACKAGE, 常量字段值
      • MODULE

        public static final int MODULE
        A single-bit mask representing module access, which may contribute to the result of lookupModes. The value is 0x10, which does not correspond meaningfully to any particular modifier bit. In conjunction with the PUBLIC modifier bit, a Lookup with this lookup mode can access all public types in the module of the lookup class and public types in packages exported by other modules to the module of the lookup class.

        If this lookup mode is set, the previous lookup class is always null.

        从以下版本开始:
        9
        另请参阅:
        MethodHandles.Lookup#MODULE, 常量字段值
      • UNCONDITIONAL

        public static final int UNCONDITIONAL
        A single-bit mask representing unconditional access which may contribute to the result of lookupModes. The value is 0x20, which does not correspond meaningfully to any particular modifier bit. A Lookup with this lookup mode assumes readability. This lookup mode can access all public members of public types of all modules when the type is in a package that is exported unconditionally.

        If this lookup mode is set, the previous lookup class is always null.

        从以下版本开始:
        9
        另请参阅:
        MethodHandles.publicLookup(), MethodHandles.Lookup#UNCONDITIONAL, 常量字段值
      • ORIGINAL

        public static final int ORIGINAL
        A single-bit mask representing original access which may contribute to the result of lookupModes. The value is 0x40, which does not correspond meaningfully to any particular modifier bit.

        If this lookup mode is set, the Lookup object must be created by the original lookup class by calling MethodHandles.lookup() method or by a bootstrap method invoked by the VM. The Lookup object with this lookup mode has full privilege access.

        从以下版本开始:
        16
        另请参阅:
        MethodHandles.Lookup#ORIGINAL, 常量字段值
      • ALL_MODES

        public static final int ALL_MODES
        A single-bit mask representing all accesses (public, private, protected and package) The value, 0x0f, happens to be the same as the value of the modifier bit.
        另请参阅:
        常量字段值
      • NOT_FOUND_METHOD_HANDLE

        public static final java.lang.invoke.MethodHandle NOT_FOUND_METHOD_HANDLE
        MethodHandle for Not-Found
    • 构造器详细资料

      • MethodHandleUtils

        public MethodHandleUtils()
    • 方法详细资料

      • lookup

        public static java.lang.invoke.MethodHandles.Lookup lookup​(java.lang.Class<?> lookupClass)
        Create an instance of MethodHandles.Lookup by the specified lookup class with all accesses (public, private, protected and package)
        参数:
        lookupClass - the lookup class
        返回:
        non-null
      • findVirtual

        public static java.lang.invoke.MethodHandle findVirtual​(java.lang.Class<?> lookupClass,
                                                                java.lang.String methodName,
                                                                java.lang.Class... parameterTypes)
        The convenient method to find MethodHandles.Lookup.findVirtual(Class, String, MethodType)
        参数:
        lookupClass - the class to be looked up
        methodName - the target method name
        parameterTypes - the types of target method parameters
        返回:
        MethodHandle
      • findStatic

        public static java.lang.invoke.MethodHandle findStatic​(java.lang.Class<?> lookupClass,
                                                               java.lang.String methodName,
                                                               java.lang.Class... parameterTypes)
        The convenient method to find MethodHandles.Lookup.findStatic(Class, String, MethodType)
        参数:
        lookupClass - the class to be looked up
        methodName - the target method name
        parameterTypes - the types of target method parameters
        返回:
        MethodHandle
      • find

        protected static java.lang.invoke.MethodHandle find​(java.lang.Class<?> lookupClass,
                                                            java.lang.String methodName,
                                                            java.lang.Class[] parameterTypes,
                                                            ThrowableBiFunction<java.lang.invoke.MethodHandles.Lookup,​java.lang.invoke.MethodType,​java.lang.invoke.MethodHandle> function)