{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ReflectiveField

public class ReflectiveField<T>


Helper class for making more performant reflection field access.

Lazy initializes and caches Method object ro attempt to reduce reflection overhead.

Summary

Public constructors

ReflectiveField(@NonNull String className, @NonNull String fieldName)

Creates a ReflectiveField.

Public methods

@NonNull T
get(@NonNull Object object)

Retrieves the field's value, initializing if necessary.

Public constructors

ReflectiveField

public ReflectiveField(@NonNull String className, @NonNull String fieldName)

Creates a ReflectiveField.

Parameters
@NonNull String className

the fully qualified class name that defines the field

@NonNull String fieldName

the field name

Public methods

get

@NonNull
public T get(@NonNull Object object)

Retrieves the field's value, initializing if necessary.

Parameters
@NonNull Object object

the object that holds the field's value

Returns
T

the field's value

Throws
androidx.test.platform.reflect.ReflectionException

if field could not be accessed