getField

open fun getField(@NonNull instance: Any, @NonNull fieldName: String): Any

Gets a field declared in the class. Please note that this does not cache the lookup result, so if you need to call this many times you should do it manually and cache the Field to improve performance drastically

Return

Data stored in the field.

Parameters

instance

Instance of the class where the field is located.

fieldName

Name of the field.

Throws

If the field doesn't exist.

If the field is inaccessible


open fun getField(@NonNull clazz: Class<out Any>, @Nullable instance: Any, @NonNull fieldName: String): Any

Gets a field declared in the class. Please note that this does not cache the lookup result, so if you need to call this many times you should do it manually and cache the Field to improve performance drastically

Return

Data stored in the field.

Parameters

clazz

Class where the field is located.

instance

Instance of the clazz or null to get static field

fieldName

Name of the field.

Throws

If the field doesn't exist.

If the field is inaccessible.