Class MethodReference

  • All Implemented Interfaces:
    java.io.Serializable

    public class MethodReference
    extends java.lang.Object
    implements java.io.Serializable

    Specifies a fully qualified name of a method, including its name, class name, parameter types and return value type. This class overloads equals and hashCode so that any two references to one method are considered equal.

    Though in Java language it is enough to have only parameter types to uniquely identify a method, JVM uses return value as well. Java generates bridge methods to make adjust the JVM's behavior.

    See Also:
    Serialized Form
    • Constructor Detail

      • MethodReference

        public MethodReference​(java.lang.String className,
                               MethodDescriptor descriptor)
      • MethodReference

        public MethodReference​(java.lang.String className,
                               java.lang.String name,
                               ValueType... signature)

        Creates a new reference to a method.

        For example, here is how you should call this constructor to create a reference to the Integer.valueOf(int) method:

         new MethodReference("java.lang.Integer", "valueOf",
                 ValueType.INT, ValueType.object("java.lang.Integer"))
         
        Parameters:
        className - the name of the class that owns the method.
        name - the name of the method.
        signature - descriptor of a method, as described in VM spec. The last element is a type of a returning value, and all the remaining elements are types of arguments.
      • MethodReference

        public MethodReference​(java.lang.Class<?> cls,
                               java.lang.String name,
                               java.lang.Class<?>... signature)
    • Method Detail

      • getClassName

        public java.lang.String getClassName()
      • parameterCount

        public int parameterCount()
      • parameterType

        public ValueType parameterType​(int index)
      • getParameterTypes

        public ValueType[] getParameterTypes()
      • getSignature

        public ValueType[] getSignature()
      • getReturnType

        public ValueType getReturnType()
      • getName

        public java.lang.String getName()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • parseIfPossible

        public static MethodReference parseIfPossible​(java.lang.String string)
      • parse

        public static MethodReference parse​(java.lang.reflect.Method method)
      • signatureToString

        public java.lang.String signatureToString()