MethodHandleInfo (Java SE 11 & JDK 11 )

    • Method Detail

      • getReferenceKind

        int getReferenceKind()

        Returns the reference kind of the cracked method handle, which in turn determines whether the method handle's underlying member was a constructor, method, or field. See the table above for definitions.

        Returns:
        the integer code for the kind of reference used to access the underlying member
      • getDeclaringClass

        Class<?> getDeclaringClass()

        Returns the class in which the cracked method handle's underlying member was defined.

        Returns:
        the declaring class of the underlying member
      • getName

        String getName()

        Returns the name of the cracked method handle's underlying member. This is "<init>" if the underlying member was a constructor, else it is a simple method name or field name.

        Returns:
        the simple name of the underlying member
      • getMethodType

        MethodType getMethodType()

        Returns the nominal type of the cracked symbolic reference, expressed as a method type. If the reference is to a constructor, the return type will be void. If it is to a non-static method, the method type will not mention the this parameter. If it is to a field and the requested access is to read the field, the method type will have no parameters and return the field type. If it is to a field and the requested access is to write the field, the method type will have one parameter of the field type and return void.

        Note that original direct method handle may include a leading this parameter, or (in the case of a constructor) will replace the void return type with the constructed class. The nominal type does not include any this parameter, and (in the case of a constructor) will return void.

        Returns:
        the type of the underlying member, expressed as a method type
      • reflectAs

        <T extends Member> T reflectAs​(Class<T> expected,
                                       MethodHandles.Lookup lookup)

        Reflects the underlying member as a method, constructor, or field object. If the underlying member is public, it is reflected as if by getMethod, getConstructor, or getField. Otherwise, it is reflected as if by getDeclaredMethod, getDeclaredConstructor, or getDeclaredField. The underlying member must be accessible to the given lookup object.

        Type Parameters:
        T - the desired type of the result, either Member or a subtype
        Parameters:
        expected - a class object representing the desired result type T
        lookup - the lookup object that created this MethodHandleInfo, or one with equivalent access privileges
        Returns:
        a reference to the method, constructor, or field object
        Throws:
        ClassCastException - if the member is not of the expected type
        NullPointerException - if either argument is null
        IllegalArgumentException - if the underlying member is not accessible to the given lookup object
      • isVarArgs

        default boolean isVarArgs()

        Determines if the underlying member was a variable arity method or constructor. Such members are represented by method handles that are varargs collectors.

        Implementation Requirements:
        This produces a result equivalent to:
        
             getReferenceKind() >= REF_invokeVirtual && Modifier.isTransient(getModifiers())
         
        Returns:
        true if and only if the underlying member was declared with variable arity.
      • referenceKindToString

        static String referenceKindToString​(int referenceKind)

        Returns the descriptive name of the given reference kind, as defined in the table above. The conventional prefix "REF_" is omitted.

        Parameters:
        referenceKind - an integer code for a kind of reference used to access a class member
        Returns:
        a mixed-case string such as "getField"
        Throws:
        IllegalArgumentException - if the argument is not a valid reference kind number