Class FieldAccessor
- java.lang.Object
-
- nl.jqno.equalsverifier.internal.reflection.FieldAccessor
-
public final class FieldAccessor extends Object
Provides reflective access to one field of an object.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canBeModifiedReflectively()
Determines whether the field can be modified using reflection.boolean
fieldIsEmptyOrSingleValueEnum()
boolean
fieldIsFinal()
boolean
fieldIsPrimitive()
boolean
fieldIsStatic()
boolean
fieldIsTransient()
Object
get(Object object)
Tries to get the field's value.Field
getField()
String
getFieldName()
Class<?>
getFieldType()
static FieldAccessor
of(Field field)
Factory method.
-
-
-
Method Detail
-
of
public static FieldAccessor of(Field field)
Factory method.- Parameters:
field
- The field to access.- Returns:
- A
FieldAccessor
forfield
.
-
getField
public Field getField()
- Returns:
- The field itself.
-
getFieldType
public Class<?> getFieldType()
- Returns:
- The field's type.
-
getFieldName
public String getFieldName()
- Returns:
- The field's name.
-
fieldIsPrimitive
public boolean fieldIsPrimitive()
- Returns:
- Whether the field is of a primitive type.
-
fieldIsFinal
public boolean fieldIsFinal()
- Returns:
- Whether the field is marked with the final modifier.
-
fieldIsStatic
public boolean fieldIsStatic()
- Returns:
- Whether the field is marked with the static modifier.
-
fieldIsTransient
public boolean fieldIsTransient()
- Returns:
- Whether the field is marked with the transient modifier.
-
fieldIsEmptyOrSingleValueEnum
public boolean fieldIsEmptyOrSingleValueEnum()
- Returns:
- Whether the field is an enum with a single value.
-
get
public Object get(Object object)
Tries to get the field's value.- Parameters:
object
- The object that contains the field whose value we want to get.- Returns:
- The field's value.
- Throws:
ReflectionException
- If the operation fails.
-
canBeModifiedReflectively
public boolean canBeModifiedReflectively()
Determines whether the field can be modified using reflection.- Returns:
- Whether or not the field can be modified reflectively.
-
-