Module java.base

Interface MethodHandleInfo


  • public interface MethodHandleInfo
    A reference to a cracked MethodHandle, which allows access to its symbolic parts. Call Lookup.revealDirect to crack a MethodHandle.
    Since:
    1.8
    • Field Detail

      • REF_getField

        static final int REF_getField
        Getter MethodHandle for an instance field
        See Also:
        Constant Field Values
      • REF_getStatic

        static final int REF_getStatic
        Getter MethodHandle for an static field
        See Also:
        Constant Field Values
      • REF_putField

        static final int REF_putField
        Setter MethodHandle for an instance field
        See Also:
        Constant Field Values
      • REF_putStatic

        static final int REF_putStatic
        Setter MethodHandle for an static field
        See Also:
        Constant Field Values
      • REF_invokeVirtual

        static final int REF_invokeVirtual
        MethodHandle for an instance method
        See Also:
        Constant Field Values
      • REF_invokeStatic

        static final int REF_invokeStatic
        MethodHandle for a static method
        See Also:
        Constant Field Values
      • REF_invokeSpecial

        static final int REF_invokeSpecial
        MethodHandle for an special method
        See Also:
        Constant Field Values
      • REF_newInvokeSpecial

        static final int REF_newInvokeSpecial
        MethodHandle for a constructor
        See Also:
        Constant Field Values
      • REF_invokeInterface

        static final int REF_invokeInterface
        MethodHandle for an interface method
        See Also:
        Constant Field Values
    • Method Detail

      • getDeclaringClass

        Class<?> getDeclaringClass()
        Returns the Class where the cracked MethodHandle's underlying method, field or constructor is declared.
        Returns:
        class that declares the underlying member
      • getName

        String getName()
        Returns the simple name of the MethodHandle's underlying member.
        Returns:
        A string representing the name of the method or field, or "<init>" for constructor.
      • getMethodType

        MethodType getMethodType()
        Returns the type of the MethodHandle's underlying member as a MethodType. If the underlying member is non-static, the receiver parameter will not be included. If the underlying member is field getter, the MethodType will take no parameters, and the return type will be the field type. If the underlying member is field setter, the MethodType will take one parameter of the field type, and the return type will be void.
        Returns:
        A MethodType object representing the signature of the method or field
      • getModifiers

        int getModifiers()
        Returns the modifiers of the MethodHandle's underlying member.
        Returns:
        An int representing the member's modifiers, or -1 if the underlying member is not accessible.
      • getReferenceKind

        int getReferenceKind()
        Returns the reference kind of the MethodHandle. The possible reference kinds are the declared MethodHandleInfo.REF fields.
        Returns:
        Returns one of the defined reference kinds which represent the MethodHandle kind.
      • isVarArgs

        default boolean isVarArgs()
        Returns whether the MethodHandle's underlying method or constructor has variable argument arity.
        Returns:
        whether the underlying method has variable arity
      • reflectAs

        <T extends Member> T reflectAs​(Class<T> expected,
                                       MethodHandles.Lookup lookup)
        Reflects the underlying member as a Method, Field or Constructor. The member must be accessible to the provided lookup object. Public members are reflected as if by getMethod, getField or getConstructor. Non-public members are reflected as if by getDeclaredMethod, getDeclaredField or getDeclaredConstructor.
        Type Parameters:
        T - The expected type of the returned Member
        Parameters:
        expected - The expected Class of the returned Member
        lookup - The lookup that was used to create the MethodHandle, or a lookup object with equivalent access
        Returns:
        A Method, Field or Constructor representing the underlying member of the MethodHandle
        Throws:
        NullPointerException - If either argument is null
        IllegalArgumentException - If the underlying member is not accessible to the provided lookup object
        ClassCastException - If the underlying member is not of the expected type
      • referenceKindToString

        static String referenceKindToString​(int referenceKind)
                                     throws IllegalArgumentException
        Returns a string representing the equivalent bytecode for the referenceKind.
        Parameters:
        referenceKind - The referenceKind to lookup
        Returns:
        a String representing the equivalent bytecode
        Throws:
        IllegalArgumentException - If the provided referenceKind is invalid
      • toString

        static String toString​(int kind,
                               Class<?> defc,
                               String name,
                               MethodType type)
        Answers a string containing a concise, human-readable description of the receiver.
        Parameters:
        kind - the reference kind, one of the declared MethodHandleInfo.REF fields.
        defc - the class where the member is declared
        name - the name of the member
        type - the member's MethodType
        Returns:
        a String of the format "K C.N:MT"