Added in API level 26

Parameter

public final class Parameter
extends Object implements AnnotatedElement

java.lang.Object
   ↳ java.lang.reflect.Parameter


Information about method parameters. A Parameter provides information about method parameters, including its name and modifiers. It also provides an alternate means of obtaining attributes for the parameter.

Summary

Public methods

boolean equals(Object obj)

Compares based on the executable and the index.

<T extends Annotation> T getAnnotation(Class<T> annotationClass)

Returns this element's annotation for the specified type if such an annotation is present, else null.

Annotation[] getAnnotations()

Returns annotations that are present on this element.

<T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass)

Returns annotations that are associated with this element.

<T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass)

Returns this element's annotation for the specified type if such an annotation is directly present, else null.

Annotation[] getDeclaredAnnotations()

Returns annotations that are directly present on this element.

<T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass)

Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present.

Executable getDeclaringExecutable()

Return the Executable which declares this parameter.

int getModifiers()

Get the modifier flags for this the parameter represented by this Parameter object.

String getName()

Returns the name of the parameter.

Type getParameterizedType()

Returns a Type object that identifies the parameterized type for the parameter represented by this Parameter object.

Class<?> getType()

Returns a Class object that identifies the declared type for the parameter represented by this Parameter object.

int hashCode()

Returns a hash code based on the executable's hash code and the index.

boolean isImplicit()

Returns true if this parameter is implicitly declared in source code; returns false otherwise.

boolean isNamePresent()

Returns true if the parameter has a name; returns false otherwise.

boolean isSynthetic()

Returns true if this parameter is neither implicitly nor explicitly declared in source code; returns false otherwise.

boolean isVarArgs()

Returns true if this parameter represents a variable argument list; returns false otherwise.

String toString()

Returns a string describing this parameter.

Inherited methods

Public methods

equals

Added in API level 26
public boolean equals (Object obj)

Compares based on the executable and the index.

Parameters
obj Object: The object to compare.

Returns
boolean Whether or not this is equal to the argument.

getAnnotation

Added in API level 26
public T getAnnotation (Class<T> annotationClass)

Returns this element's annotation for the specified type if such an annotation is present, else null.

Parameters
annotationClass Class: the Class object corresponding to the annotation type

Returns
T this element's annotation for the specified annotation type if present on this element, else null

Throws
NullPointerException

getAnnotations

Added in API level 26
public Annotation[] getAnnotations ()

Returns annotations that are present on this element. If there are no annotations present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Returns
Annotation[] annotations present on this element

getAnnotationsByType

Added in API level 26
public T[] getAnnotationsByType (Class<T> annotationClass)

Returns annotations that are associated with this element. If there are no annotations associated with this element, the return value is an array of length 0. The difference between this method and getAnnotation(java.lang.Class) is that this method detects if its argument is a repeatable annotation type (JLS 9.6), and if so, attempts to find one or more annotations of that type by "looking through" a container annotation. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Parameters
annotationClass Class: the Class object corresponding to the annotation type

Returns
T[] all this element's annotations for the specified annotation type if associated with this element, else an array of length zero

Throws
NullPointerException

getDeclaredAnnotation

Added in API level 26
public T getDeclaredAnnotation (Class<T> annotationClass)

Returns this element's annotation for the specified type if such an annotation is directly present, else null. This method ignores inherited annotations. (Returns null if no annotations are directly present on this element.)

Parameters
annotationClass Class: the Class object corresponding to the annotation type

Returns
T this element's annotation for the specified annotation type if directly present on this element, else null

Throws
NullPointerException

getDeclaredAnnotations

Added in API level 26
public Annotation[] getDeclaredAnnotations ()

Returns annotations that are directly present on this element. This method ignores inherited annotations. If there are no annotations directly present on this element, the return value is an array of length 0. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Returns
Annotation[] annotations directly present on this element

getDeclaredAnnotationsByType

Added in API level 26
public T[] getDeclaredAnnotationsByType (Class<T> annotationClass)

Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present. This method ignores inherited annotations. If there are no specified annotations directly or indirectly present on this element, the return value is an array of length 0. The difference between this method and getDeclaredAnnotation(java.lang.Class) is that this method detects if its argument is a repeatable annotation type (JLS 9.6), and if so, attempts to find one or more annotations of that type by "looking through" a container annotation if one is present. The caller of this method is free to modify the returned array; it will have no effect on the arrays returned to other callers.

Parameters
annotationClass Class: the Class object corresponding to the annotation type

Returns
T[] all this element's annotations for the specified annotation type if directly or indirectly present on this element, else an array of length zero

Throws
NullPointerException

getDeclaringExecutable

Added in API level 26
public Executable getDeclaringExecutable ()

Return the Executable which declares this parameter.

Returns
Executable The Executable declaring this parameter.

getModifiers

Added in API level 26
public int getModifiers ()

Get the modifier flags for this the parameter represented by this Parameter object.

Returns
int The modifier flags for this parameter.

getName

Added in API level 26
public String getName ()

Returns the name of the parameter. If the parameter's name is present, then this method returns the name provided by the class file. Otherwise, this method synthesizes a name of the form argN, where N is the index of the parameter in the descriptor of the method which declares the parameter.

Returns
String The name of the parameter, either provided by the class file or synthesized if the class file does not provide a name.

getParameterizedType

Added in API level 26
public Type getParameterizedType ()

Returns a Type object that identifies the parameterized type for the parameter represented by this Parameter object.

Returns
Type a Type object identifying the parameterized type of the parameter represented by this object

getType

Added in API level 26
public Class<?> getType ()

Returns a Class object that identifies the declared type for the parameter represented by this Parameter object.

Returns
Class<?> a Class object identifying the declared type of the parameter represented by this object

hashCode

Added in API level 26
public int hashCode ()

Returns a hash code based on the executable's hash code and the index.

Returns
int A hash code based on the executable's hash code.

isImplicit

Added in API level 26
public boolean isImplicit ()

Returns true if this parameter is implicitly declared in source code; returns false otherwise.

Returns
boolean true if and only if this parameter is implicitly declared as defined by The Java™ Language Specification.

isNamePresent

Added in API level 26
public boolean isNamePresent ()

Returns true if the parameter has a name; returns false otherwise. Whether a parameter has a name is determined by compiler options and whether the parameter is synthesized.

Returns
boolean true if and only if the parameter has a name

isSynthetic

Added in API level 26
public boolean isSynthetic ()

Returns true if this parameter is neither implicitly nor explicitly declared in source code; returns false otherwise.

Returns
boolean true if and only if this parameter is a synthetic construct as defined by The Java™ Language Specification.

isVarArgs

Added in API level 26
public boolean isVarArgs ()

Returns true if this parameter represents a variable argument list; returns false otherwise.

Returns
boolean true if an only if this parameter represents a variable argument list.

toString

Added in API level 26
public String toString ()

Returns a string describing this parameter. The format is the modifiers for the parameter, if any, in canonical order as recommended by The Java™ Language Specification, followed by the fully- qualified type of the parameter (excluding the last [] if the parameter is variable arity), followed by "..." if the parameter is variable arity, followed by a space, followed by the name of the parameter.

Returns
String A string representation of the parameter and associated information.