org.springframework.core

## 类 MethodParameter

- java.lang.Object
- - org.springframework.core.MethodParameter

- 直接已知子类:
    SynthesizingMethodParameter

      public class MethodParameter
      extends Object

  Helper class that encapsulates the specification of a method parameter, i.e. a `Method` or `Constructor` plus a parameter index and a nested type index for a declared generic type. Useful as a specification object to pass along.

  As of 4.2, there is a `SynthesizingMethodParameter` subclass available which synthesizes annotations with attribute aliases. That subclass is used for web and message endpoint processing, in particular.

  从以下版本开始:
    2.0
  作者:
    Juergen Hoeller, Rob Harrop, Andy Clement, Sam Brannen, Sebastien Deleuze
  另请参阅:
    `SynthesizingMethodParameter`

- - ### 构造器概要

    构造器
    构造器和说明
    `MethodParameter(Constructor<?> constructor, int parameterIndex)` Create a new MethodParameter for the given constructor, with nesting level 1.
    `MethodParameter(Constructor<?> constructor, int parameterIndex, int nestingLevel)` Create a new MethodParameter for the given constructor.
    `MethodParameter(Method method, int parameterIndex)` Create a new `MethodParameter` for the given method, with nesting level 1.
    `MethodParameter(Method method, int parameterIndex, int nestingLevel)` Create a new `MethodParameter` for the given method.
    `MethodParameter(MethodParameter original)` Copy constructor, resulting in an independent MethodParameter object based on the same metadata and cache state that the original object was in.

  - ### 方法概要

    所有方法 静态方法 实例方法 具体方法 已过时的方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected <A extends Annotation> A` | `adaptAnnotation(A annotation)` A template method to post-process a given annotation instance before returning it to the caller.
    `protected Annotation[]` | `adaptAnnotationArray(Annotation[] annotations)` A template method to post-process a given annotation array before returning it to the caller.
    `MethodParameter` | `clone()`
    `void` | `decreaseNestingLevel()` Decrease this parameter's nesting level.
    `boolean` | `equals(Object other)`
    `protected static int` | `findParameterIndex(Parameter parameter)`
    `static MethodParameter` | `forExecutable(Executable executable, int parameterIndex)` Create a new MethodParameter for the given method or constructor.
    `static MethodParameter` | `forMethodOrConstructor(Object methodOrConstructor, int parameterIndex)` 已过时。 as of 5.0, in favor of `forExecutable(java.lang.reflect.Executable, int)`
    `static MethodParameter` | `forParameter(Parameter parameter)` Create a new MethodParameter for the given parameter descriptor.
    `AnnotatedElement` | `getAnnotatedElement()` Return the wrapped annotated element.
    `Constructor<?>` | `getConstructor()` Return the wrapped Constructor, if any.
    `Class<?>` | `getContainingClass()`
    `Class<?>` | `getDeclaringClass()` Return the class that declares the underlying Method or Constructor.
    `Executable` | `getExecutable()` Return the wrapped executable.
    `Type` | `getGenericParameterType()` Return the generic type of the method/constructor parameter.
    `Member` | `getMember()` Return the wrapped member.
    `Method` | `getMethod()` Return the wrapped Method, if any.
    `<A extends Annotation> A` | `getMethodAnnotation(Class<A> annotationType)` Return the method/constructor annotation of the given type, if available.
    `Annotation[]` | `getMethodAnnotations()` Return the annotations associated with the target method/constructor itself.
    `Type` | `getNestedGenericParameterType()` Return the nested generic type of the method/constructor parameter.
    `Class<?>` | `getNestedParameterType()` Return the nested type of the method/constructor parameter.
    `int` | `getNestingLevel()` Return the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List).
    `Parameter` | `getParameter()` Return the `Parameter` descriptor for method/constructor parameter.
    `<A extends Annotation> A` | `getParameterAnnotation(Class<A> annotationType)` Return the parameter annotation of the given type, if available.
    `Annotation[]` | `getParameterAnnotations()` Return the annotations associated with the specific method/constructor parameter.
    `int` | `getParameterIndex()` Return the index of the method/constructor parameter.
    `String` | `getParameterName()` Return the name of the method/constructor parameter.
    `Class<?>` | `getParameterType()` Return the type of the method/constructor parameter.
    `Integer` | `getTypeIndexForCurrentLevel()` Return the type index for the current nesting level.
    `Integer` | `getTypeIndexForLevel(int nestingLevel)` Return the type index for the specified nesting level.
    `int` | `hashCode()`
    `<A extends Annotation> boolean` | `hasMethodAnnotation(Class<A> annotationType)` Return whether the method/constructor is annotated with the given type.
    `<A extends Annotation> boolean` | `hasParameterAnnotation(Class<A> annotationType)` Return whether the parameter is declared with the given annotation type.
    `boolean` | `hasParameterAnnotations()` Return `true` if the parameter has at least one annotation, `false` if it has none.
    `void` | `increaseNestingLevel()` Increase this parameter's nesting level.
    `void` | `initParameterNameDiscovery(ParameterNameDiscoverer parameterNameDiscoverer)` Initialize parameter name discovery for this method parameter.
    `boolean` | `isOptional()` Return whether this method indicates a parameter which is not required: either in the form of Java 8's `Optional`, any variant of a parameter-level `Nullable` annotation (such as from JSR-305 or the FindBugs set of annotations), or a language-level nullable type declaration in Kotlin.
    `MethodParameter` | `nested()` Return a variant of this `MethodParameter` which points to the same parameter but one nesting level deeper.
    `MethodParameter` | `nestedIfOptional()` Return a variant of this `MethodParameter` which points to the same parameter but one nesting level deeper in case of a `Optional` declaration.
    `void` | `setTypeIndexForCurrentLevel(int typeIndex)` Set the type index for the current nesting level.
    `String` | `toString()`

    - ### 从类继承的方法 java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### 构造器详细资料

    - #### MethodParameter

          public MethodParameter(Method method,
                                 int parameterIndex)

      Create a new `MethodParameter` for the given method, with nesting level 1.
      参数:
        `method` - the Method to specify a parameter for
        `parameterIndex` - the index of the parameter: -1 for the method return type; 0 for the first method parameter; 1 for the second method parameter, etc.

    - #### MethodParameter

          public MethodParameter(Method method,
                                 int parameterIndex,
                                 int nestingLevel)

      Create a new `MethodParameter` for the given method.
      参数:
        `method` - the Method to specify a parameter for
        `parameterIndex` - the index of the parameter: -1 for the method return type; 0 for the first method parameter; 1 for the second method parameter, etc.
        `nestingLevel` - the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List)

    - #### MethodParameter

          public MethodParameter(Constructor<?> constructor,
                                 int parameterIndex)

      Create a new MethodParameter for the given constructor, with nesting level 1.
      参数:
        `constructor` - the Constructor to specify a parameter for
        `parameterIndex` - the index of the parameter

    - #### MethodParameter

          public MethodParameter(Constructor<?> constructor,
                                 int parameterIndex,
                                 int nestingLevel)

      Create a new MethodParameter for the given constructor.
      参数:
        `constructor` - the Constructor to specify a parameter for
        `parameterIndex` - the index of the parameter
        `nestingLevel` - the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List)

    - #### MethodParameter

          public MethodParameter(MethodParameter original)

      Copy constructor, resulting in an independent MethodParameter object based on the same metadata and cache state that the original object was in.
      参数:
        `original` - the original MethodParameter object to copy from

  - ### 方法详细资料

    - #### getMethod

          @Nullable
          public Method getMethod()

      Return the wrapped Method, if any.

      Note: Either Method or Constructor is available.

      返回:
        the Method, or `null` if none

    - #### getConstructor

          @Nullable
          public Constructor<?> getConstructor()

      Return the wrapped Constructor, if any.

      Note: Either Method or Constructor is available.

      返回:
        the Constructor, or `null` if none

    - #### getDeclaringClass

          public Class<?> getDeclaringClass()

      Return the class that declares the underlying Method or Constructor.

    - #### getMember

          public Member getMember()

      Return the wrapped member.
      返回:
        the Method or Constructor as Member

    - #### getAnnotatedElement

          public AnnotatedElement getAnnotatedElement()

      Return the wrapped annotated element.

      Note: This method exposes the annotations declared on the method/constructor itself (i.e. at the method/constructor level, not at the parameter level).

      返回:
        the Method or Constructor as AnnotatedElement

    - #### getExecutable

          public Executable getExecutable()

      Return the wrapped executable.
      返回:
        the Method or Constructor as Executable
      从以下版本开始:
        5.0

    - #### getParameter

          public Parameter getParameter()

      Return the `Parameter` descriptor for method/constructor parameter.
      从以下版本开始:
        5.0

    - #### getParameterIndex

          public int getParameterIndex()

      Return the index of the method/constructor parameter.
      返回:
        the parameter index (-1 in case of the return type)

    - #### increaseNestingLevel

          public void increaseNestingLevel()

      Increase this parameter's nesting level.
      另请参阅:
        `getNestingLevel()`

    - #### decreaseNestingLevel

          public void decreaseNestingLevel()

      Decrease this parameter's nesting level.
      另请参阅:
        `getNestingLevel()`

    - #### getNestingLevel

          public int getNestingLevel()

      Return the nesting level of the target type (typically 1; e.g. in case of a List of Lists, 1 would indicate the nested List, whereas 2 would indicate the element of the nested List).

    - #### setTypeIndexForCurrentLevel

          public void setTypeIndexForCurrentLevel(int typeIndex)

      Set the type index for the current nesting level.
      参数:
        `typeIndex` - the corresponding type index (or `null` for the default type index)
      另请参阅:
        `getNestingLevel()`

    - #### getTypeIndexForCurrentLevel

          @Nullable
          public Integer getTypeIndexForCurrentLevel()

      Return the type index for the current nesting level.
      返回:
        the corresponding type index, or `null` if none specified (indicating the default type index)
      另请参阅:
        `getNestingLevel()`

    - #### getTypeIndexForLevel

          @Nullable
          public Integer getTypeIndexForLevel(int nestingLevel)

      Return the type index for the specified nesting level.
      参数:
        `nestingLevel` - the nesting level to check
      返回:
        the corresponding type index, or `null` if none specified (indicating the default type index)

    - #### nested

          public MethodParameter nested()

      Return a variant of this `MethodParameter` which points to the same parameter but one nesting level deeper. This is effectively the same as `increaseNestingLevel()`, just with an independent `MethodParameter` object (e.g. in case of the original being cached).
      从以下版本开始:
        4.3

    - #### isOptional

          public boolean isOptional()

      Return whether this method indicates a parameter which is not required: either in the form of Java 8's `Optional`, any variant of a parameter-level `Nullable` annotation (such as from JSR-305 or the FindBugs set of annotations), or a language-level nullable type declaration in Kotlin.
      从以下版本开始:
        4.3

    - #### nestedIfOptional

          public MethodParameter nestedIfOptional()

      Return a variant of this `MethodParameter` which points to the same parameter but one nesting level deeper in case of a `Optional` declaration.
      从以下版本开始:
        4.3
      另请参阅:
        `isOptional()`, `nested()`

    - #### getContainingClass

          public Class<?> getContainingClass()

    - #### getParameterType

          public Class<?> getParameterType()

      Return the type of the method/constructor parameter.
      返回:
        the parameter type (never `null`)

    - #### getGenericParameterType

          public Type getGenericParameterType()

      Return the generic type of the method/constructor parameter.
      返回:
        the parameter type (never `null`)
      从以下版本开始:
        3.0

    - #### getNestedParameterType

          public Class<?> getNestedParameterType()

      Return the nested type of the method/constructor parameter.
      返回:
        the parameter type (never `null`)
      从以下版本开始:
        3.1
      另请参阅:
        `getNestingLevel()`

    - #### getNestedGenericParameterType

          public Type getNestedGenericParameterType()

      Return the nested generic type of the method/constructor parameter.
      返回:
        the parameter type (never `null`)
      从以下版本开始:
        4.2
      另请参阅:
        `getNestingLevel()`

    - #### getMethodAnnotations

          public Annotation[] getMethodAnnotations()

      Return the annotations associated with the target method/constructor itself.

    - #### getMethodAnnotation

          @Nullable
          public <A extends Annotation> A getMethodAnnotation(Class<A> annotationType)

      Return the method/constructor annotation of the given type, if available.
      参数:
        `annotationType` - the annotation type to look for
      返回:
        the annotation object, or `null` if not found

    - #### hasMethodAnnotation

          public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType)

      Return whether the method/constructor is annotated with the given type.
      参数:
        `annotationType` - the annotation type to look for
      从以下版本开始:
        4.3
      另请参阅:
        `getMethodAnnotation(Class)`

    - #### getParameterAnnotations

          public Annotation[] getParameterAnnotations()

      Return the annotations associated with the specific method/constructor parameter.

    - #### hasParameterAnnotations

          public boolean hasParameterAnnotations()

      Return `true` if the parameter has at least one annotation, `false` if it has none.
      另请参阅:
        `getParameterAnnotations()`

    - #### getParameterAnnotation

          @Nullable
          public <A extends Annotation> A getParameterAnnotation(Class<A> annotationType)

      Return the parameter annotation of the given type, if available.
      参数:
        `annotationType` - the annotation type to look for
      返回:
        the annotation object, or `null` if not found

    - #### hasParameterAnnotation

          public <A extends Annotation> boolean hasParameterAnnotation(Class<A> annotationType)

      Return whether the parameter is declared with the given annotation type.
      参数:
        `annotationType` - the annotation type to look for
      另请参阅:
        `getParameterAnnotation(Class)`

    - #### initParameterNameDiscovery

          public void initParameterNameDiscovery(@Nullable
                                                 ParameterNameDiscoverer parameterNameDiscoverer)

      Initialize parameter name discovery for this method parameter.

      This method does not actually try to retrieve the parameter name at this point; it just allows discovery to happen when the application calls `getParameterName()` (if ever).

    - #### getParameterName

          @Nullable
          public String getParameterName()

      Return the name of the method/constructor parameter.
      返回:
        the parameter name (may be `null` if no parameter name metadata is contained in the class file or no `ParameterNameDiscoverer` has been set to begin with)

    - #### adaptAnnotation

          protected <A extends Annotation> A adaptAnnotation(A annotation)

      A template method to post-process a given annotation instance before returning it to the caller.

      The default implementation simply returns the given annotation as-is.

      参数:
        `annotation` - the annotation about to be returned
      返回:
        the post-processed annotation (or simply the original one)
      从以下版本开始:
        4.2

    - #### adaptAnnotationArray

          protected Annotation[] adaptAnnotationArray(Annotation[] annotations)

      A template method to post-process a given annotation array before returning it to the caller.

      The default implementation simply returns the given annotation array as-is.

      参数:
        `annotations` - the annotation array about to be returned
      返回:
        the post-processed annotation array (or simply the original one)
      从以下版本开始:
        4.2

    - #### equals

          public boolean equals(Object other)

      覆盖:
        `equals` 在类中 `Object`

    - #### hashCode

          public int hashCode()

      覆盖:
        `hashCode` 在类中 `Object`

    - #### toString

          public String toString()

      覆盖:
        `toString` 在类中 `Object`

    - #### clone

          public MethodParameter clone()

      覆盖:
        `clone` 在类中 `Object`

    - #### forMethodOrConstructor

          @Deprecated
          public static MethodParameter forMethodOrConstructor(Object methodOrConstructor,
                                                                            int parameterIndex)

      已过时。 as of 5.0, in favor of `forExecutable(java.lang.reflect.Executable, int)`
      Create a new MethodParameter for the given method or constructor.

      This is a convenience factory method for scenarios where a Method or Constructor reference is treated in a generic fashion.

      参数:
        `methodOrConstructor` - the Method or Constructor to specify a parameter for
        `parameterIndex` - the index of the parameter
      返回:
        the corresponding MethodParameter instance

    - #### forExecutable

          public static MethodParameter forExecutable(Executable executable,
                                                      int parameterIndex)

      Create a new MethodParameter for the given method or constructor.

      This is a convenience factory method for scenarios where a Method or Constructor reference is treated in a generic fashion.

      参数:
        `executable` - the Method or Constructor to specify a parameter for
        `parameterIndex` - the index of the parameter
      返回:
        the corresponding MethodParameter instance
      从以下版本开始:
        5.0

    - #### forParameter

          public static MethodParameter forParameter(Parameter parameter)

      Create a new MethodParameter for the given parameter descriptor.

      This is a convenience factory method for scenarios where a Java 8 `Parameter` descriptor is already available.

      参数:
        `parameter` - the parameter descriptor
      返回:
        the corresponding MethodParameter instance
      从以下版本开始:
        5.0

    - #### findParameterIndex

          protected static int findParameterIndex(Parameter parameter)