Class Parameter
- All Implemented Interfaces:
AnnotatedElement
public final class Parameter extends Object implements AnnotatedElement
Parameter provides information about method parameters, including its name and modifiers. It also provides an alternate means of obtaining attributes for the parameter.- Since:
- 1.8
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals |
Compares based on the executable and the index. |
AnnotatedType |
getAnnotatedType() |
Returns an AnnotatedType object that represents the use of a type to specify the type of the formal parameter represented by this Parameter. |
<T extends Annotation> |
getAnnotation |
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> |
getAnnotationsByType |
Returns annotations that are associated with this element. |
<T extends Annotation> |
getDeclaredAnnotation |
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> |
getDeclaredAnnotationsByType |
Returns this element's annotation(s) for the specified type if such annotations are either directly present or indirectly present. |
Executable |
getDeclaringExecutable() |
Returns the Executable declaring this parameter. |
int |
getModifiers() |
Returns the Java language modifiers for the parameter represented by this 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 according to the class file; 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. |
Methods declared in class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods declared in interface java.lang.reflect.AnnotatedElement
isAnnotationPresent
Method Details
equals
public boolean equals(Object obj)
hashCode
public int hashCode()
isNamePresent
public boolean isNamePresent()
- Returns:
- true if and only if the parameter has a name according to the class file.
toString
public String toString()
getDeclaringExecutable
public Executable getDeclaringExecutable()
Executable declaring this parameter.- Returns:
- the
Executabledeclaring this parameter
getModifiers
public int getModifiers()
- Returns:
- the Java language modifiers for the parameter represented by this object
- See Java Language Specification:
- 8.4.1 Formal Parameters
- See Also:
getName
public String getName()
- Returns:
- The name of the parameter, either provided by the class file or synthesized if the class file does not provide a name.
getParameterizedType
public Type getParameterizedType()
Type object that identifies the parameterized type for the parameter represented by this Parameter object.- Returns:
- a
Typeobject identifying the parameterized type of the parameter represented by this object
getType
public Class<?> getType()
Class object that identifies the declared type for the parameter represented by this Parameter object.- Returns:
- a
Classobject identifying the declared type of the parameter represented by this object
getAnnotatedType
public AnnotatedType getAnnotatedType()
- Returns:
- an
AnnotatedTypeobject representing the use of a type to specify the type of the formal parameter represented by this Parameter
isImplicit
public boolean isImplicit()
true if this parameter is implicitly declared in source code; returns false otherwise.- Returns:
- true if and only if this parameter is implicitly declared as defined by The Java Language Specification.
isSynthetic
public boolean isSynthetic()
true if this parameter is neither implicitly nor explicitly declared in source code; returns false otherwise.- Returns:
- true if and only if this parameter is a synthetic construct as defined by The Java Language Specification.
- See Java Language Specification:
- 13.1 The Form of a Binary
- See Also:
isVarArgs
public boolean isVarArgs()
true if this parameter represents a variable argument list; returns false otherwise.- Returns:
-
trueif an only if this parameter represents a variable argument list.
getAnnotation
public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
Note that any annotation returned by this method is a declaration annotation.
- Specified by:
-
getAnnotationin interfaceAnnotatedElement - Type Parameters:
-
T- the type of the annotation to query for and return if present - Parameters:
-
annotationClass- the Class object corresponding to the annotation type - Returns:
- this element's annotation for the specified annotation type if present on this element, else null
- Throws:
-
NullPointerException- if the given annotation class is null
getAnnotationsByType
public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass)
AnnotatedElement.getAnnotation(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. Note that any annotations returned by this method are declaration annotations.
- Specified by:
-
getAnnotationsByTypein interfaceAnnotatedElement - Type Parameters:
-
T- the type of the annotation to query for and return if present - Parameters:
-
annotationClass- the Class object corresponding to the annotation type - Returns:
- all this element's annotations for the specified annotation type if associated with this element, else an array of length zero
- Throws:
-
NullPointerException- if the given annotation class is null
getDeclaredAnnotations
public Annotation[] getDeclaredAnnotations()
Note that any annotations returned by this method are declaration annotations.
- Specified by:
-
getDeclaredAnnotationsin interfaceAnnotatedElement - Returns:
- annotations directly present on this element
getDeclaredAnnotation
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass)
Note that any annotation returned by this method is a declaration annotation.
- Specified by:
-
getDeclaredAnnotationin interfaceAnnotatedElement - Type Parameters:
-
T- the type of the annotation to query for and return if directly present - Parameters:
-
annotationClass- the Class object corresponding to the annotation type - Returns:
- this element's annotation for the specified annotation type if directly present on this element, else null
- Throws:
-
NullPointerException- if the given annotation class is null
getDeclaredAnnotationsByType
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass)
AnnotatedElement.getDeclaredAnnotation(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. Note that any annotations returned by this method are declaration annotations.
- Specified by:
-
getDeclaredAnnotationsByTypein interfaceAnnotatedElement - Type Parameters:
-
T- the type of the annotation to query for and return if directly or indirectly present - Parameters:
-
annotationClass- the Class object corresponding to the annotation type - Returns:
- 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- if the given annotation class is null
getAnnotations
public Annotation[] getAnnotations()
Note that any annotations returned by this method are declaration annotations.
- Specified by:
-
getAnnotationsin interfaceAnnotatedElement - Returns:
- annotations present on this element
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/reflect/Parameter.html