Added in API level 34

RecordComponent

class RecordComponent : AnnotatedElement
kotlin.Any
   ↳ java.lang.reflect.RecordComponent

A RecordComponent provides information about, and dynamic access to, a component of a record class.

Summary

Public methods
Method

Returns a Method that represents the accessor for this record component.

T?
getAnnotation(annotationClass: Class<T>)

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

Array<Annotation!>

Returns annotations that are present on this element.

Array<Annotation!>

Returns annotations that are directly present on this element.

Class<*>

Returns the record class which declares this record component.

String?

Returns a String that describes the generic type signature for this record component.

Type

Returns a Type object that represents the declared type for this record component.

String

Returns the name of this record component.

Class<*>

Returns a Class that identifies the declared type for this record component.

String

Returns a string describing this record component.

Inherited functions

Public methods

getAccessor

Added in API level 34
fun getAccessor(): Method

Returns a Method that represents the accessor for this record component.

Return
Method a Method that represents the accessor for this record component

getAnnotation

Added in API level 34
fun <T : Annotation!> getAnnotation(annotationClass: Class<T>): T?

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

Note that any annotation returned by this method is a declaration annotation.

Parameters
<T> the type of the annotation to query for and return if present
annotationClass Class<T>: the Class object corresponding to the annotation type
Return
T? this element's annotation for the specified annotation type if present on this element, else null
Exceptions
java.lang.NullPointerException if the given annotation class is null

getAnnotations

Added in API level 34
fun getAnnotations(): Array<Annotation!>

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.

Note that any annotations returned by this method are declaration annotations.

Return
Array<Annotation!> annotations present on this element

getDeclaredAnnotations

Added in API level 34
fun getDeclaredAnnotations(): Array<Annotation!>

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.

Note that any annotations returned by this method are declaration annotations.

Return
Array<Annotation!> annotations directly present on this element

getDeclaringRecord

Added in API level 34
fun getDeclaringRecord(): Class<*>

Returns the record class which declares this record component.

Return
Class<*> The record class declaring this record component.

getGenericSignature

Added in API level 34
fun getGenericSignature(): String?

Returns a String that describes the generic type signature for this record component.

Return
String? a String that describes the generic type signature for this record component

getGenericType

Added in API level 34
fun getGenericType(): Type

Returns a Type object that represents the declared type for this record component.

If the declared type of the record component is a parameterized type, the Type object returned reflects the actual type arguments used in the source code.

If the type of the underlying record component is a type variable or a parameterized type, it is created. Otherwise, it is resolved.

Return
Type a Type object that represents the declared type for this record component
Exceptions
java.lang.reflect.GenericSignatureFormatError if the generic record component signature does not conform to the format specified in The Java Virtual Machine Specification
java.lang.TypeNotPresentException if the generic type signature of the underlying record component refers to a non-existent type declaration
java.lang.reflect.MalformedParameterizedTypeException if the generic signature of the underlying record component refers to a parameterized type that cannot be instantiated for any reason

getName

Added in API level 34
fun getName(): String

Returns the name of this record component.

Return
String the name of this record component

getType

Added in API level 34
fun getType(): Class<*>

Returns a Class that identifies the declared type for this record component.

Return
Class<*> a Class identifying the declared type of the component represented by this record component

toString

Added in API level 34
fun toString(): String

Returns a string describing this record component. The format is the record component type, followed by a space, followed by the name of the record component. For example:

java.lang.String name
     int age
  

Return
String a string describing this record component