public final class Field extends AccessibleObject implements Member
| Modifier and Type | Field and Description |
|---|---|
static Comparator<Field> |
ORDER_BY_NAME_AND_DECLARING_CLASS
Orders fields by their name and declaring class.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object other)
Returns true if
other has the same declaring class, name and type
as this field. |
Object |
get(Object object)
Returns the value of the field in the specified object.
|
<A extends Annotation> |
getAnnotation(Class<A> annotationType)
Returns, for this element, the annotation with the specified type, or
null if no annotation with the specified type is present
(including inherited annotations). |
boolean |
getBoolean(Object object)
Returns the value of the field in the specified object as a
boolean. |
byte |
getByte(Object object)
Returns the value of the field in the specified object as a
byte. |
char |
getChar(Object object)
Returns the value of the field in the specified object as a
char. |
Annotation[] |
getDeclaredAnnotations()
Returns, for this element, all annotations that are explicitly declared
(not inherited).
|
Class<?> |
getDeclaringClass()
Returns the class that declares this member.
|
int |
getDexFieldIndex()
Returns the index of this field's ID in its dex file.
|
double |
getDouble(Object object)
Returns the value of the field in the specified object as a
double. |
float |
getFloat(Object object)
Returns the value of the field in the specified object as a
float
. |
Type |
getGenericType()
Returns the generic type of this field.
|
int |
getInt(Object object)
Returns the value of the field in the specified object as an
int. |
long |
getLong(Object object)
Returns the value of the field in the specified object as a
long. |
int |
getModifiers()
Returns the modifiers for this field.
|
String |
getName()
Returns the name of this field.
|
int |
getOffset()
Returns the offset of the field within an instance, or for static fields, the class.
|
short |
getShort(Object object)
Returns the value of the field in the specified object as a
short
. |
Class<?> |
getType()
Return the
Class associated with the type of this field. |
int |
hashCode()
Returns an integer hash code for this object.
|
boolean |
isAnnotationPresent(Class<? extends Annotation> annotationType)
Indicates whether or not this element has an annotation with the
specified annotation type (including inherited annotations).
|
boolean |
isEnumConstant()
Indicates whether or not this field is an enumeration constant.
|
boolean |
isSynthetic()
Indicates whether or not this field is synthetic.
|
void |
set(Object object,
Object value)
Sets the value of the field in the specified object to the value.
|
void |
setBoolean(Object object,
boolean value)
Sets the value of the field in the specified object to the
boolean value. |
void |
setByte(Object object,
byte value)
Sets the value of the field in the specified object to the
byte
value. |
void |
setChar(Object object,
char value)
Sets the value of the field in the specified object to the
char
value. |
void |
setDouble(Object object,
double value)
Sets the value of the field in the specified object to the
double
value. |
void |
setFloat(Object object,
float value)
Sets the value of the field in the specified object to the
float
value. |
void |
setInt(Object object,
int value)
Set the value of the field in the specified object to the
int
value. |
void |
setLong(Object object,
long value)
Sets the value of the field in the specified object to the
long
value. |
void |
setShort(Object object,
short value)
Sets the value of the field in the specified object to the
short
value. |
String |
toGenericString()
Returns the string representation of this field, including the field's
generic type.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
field.
|
getAnnotations, isAccessible, setAccessible, setAccessiblepublic static final Comparator<Field> ORDER_BY_NAME_AND_DECLARING_CLASS
public int getModifiers()
Modifier class should
be used to decode the result.getModifiers in interface MemberModifierpublic boolean isEnumConstant()
true if this field is an enumeration constant, false otherwisepublic boolean isSynthetic()
isSynthetic in interface Membertrue if this field is synthetic, false otherwisepublic String getName()
public Class<?> getDeclaringClass()
MembergetDeclaringClass in interface Memberpublic Class<?> getType()
Class associated with the type of this field.public int getDexFieldIndex()
public int getOffset()
public int hashCode()
Object.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
Equivalent to getDeclaringClass().getName().hashCode() ^ getName().hashCode().
hashCode in class ObjectObject.equals(java.lang.Object)public boolean equals(Object other)
other has the same declaring class, name and type
as this field.equals in class Objectother - the object to compare this instance with.true if the specified object is equal to this Object; false otherwise.Object.hashCode()public String toGenericString()
public Type getGenericType()
GenericSignatureFormatError - if the generic field signature is invalidTypeNotPresentException - if the generic type points to a missing typeMalformedParameterizedTypeException - if the generic type points to a type that cannot be
instantiated for some reasonpublic Annotation[] getDeclaredAnnotations()
AnnotatedElementgetDeclaredAnnotations in interface AnnotatedElementgetDeclaredAnnotations in class AccessibleObjectpublic <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElementnull if no annotation with the specified type is present
(including inherited annotations).getAnnotation in interface AnnotatedElementgetAnnotation in class AccessibleObjectannotationType - the type of the annotation to search fornullpublic boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
AnnotatedElementisAnnotationPresent in interface AnnotatedElementisAnnotationPresent in class AccessibleObjectannotationType - the type of the annotation to search fortrue if the annotation exists, false otherwisepublic Object get(Object object) throws IllegalAccessException, IllegalArgumentException
object.fieldName
If the type of this field is a primitive type, the field value is automatically boxed.
If this field is static, the object argument is ignored. Otherwise, if the object is null, a NullPointerException is thrown. If the object is not an instance of the declaring class of the method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic boolean getBoolean(Object object) throws IllegalAccessException, IllegalArgumentException
boolean. This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic byte getByte(Object object) throws IllegalAccessException, IllegalArgumentException
byte.
This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic char getChar(Object object) throws IllegalAccessException, IllegalArgumentException
char.
This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic double getDouble(Object object) throws IllegalAccessException, IllegalArgumentException
double. This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic float getFloat(Object object) throws IllegalAccessException, IllegalArgumentException
float
. This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic int getInt(Object object) throws IllegalAccessException, IllegalArgumentException
int.
This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic long getLong(Object object) throws IllegalAccessException, IllegalArgumentException
long.
This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic short getShort(Object object) throws IllegalAccessException, IllegalArgumentException
short
. This reproduces the effect of object.fieldName
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
object - the object to accessNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void set(Object object, Object value) throws IllegalAccessException, IllegalArgumentException
object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the field type is a primitive type, the value is automatically unboxed. If the unboxing fails, an IllegalArgumentException is thrown. If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setBoolean(Object object, boolean value) throws IllegalAccessException, IllegalArgumentException
boolean value. This reproduces the effect of object.fieldName =
value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setByte(Object object, byte value) throws IllegalAccessException, IllegalArgumentException
byte
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setChar(Object object, char value) throws IllegalAccessException, IllegalArgumentException
char
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setDouble(Object object, double value) throws IllegalAccessException, IllegalArgumentException
double
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setFloat(Object object, float value) throws IllegalAccessException, IllegalArgumentException
float
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setInt(Object object, int value) throws IllegalAccessException, IllegalArgumentException
int
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setLong(Object object, long value) throws IllegalAccessException, IllegalArgumentException
long
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic void setShort(Object object, short value) throws IllegalAccessException, IllegalArgumentException
short
value. This reproduces the effect of object.fieldName = value
If this field is static, the object argument is ignored.
Otherwise, if the object is null, a NullPointerException is
thrown. If the object is not an instance of the declaring class of the
method, an IllegalArgumentException is thrown.
If this Field object is enforcing access control (see AccessibleObject) and this field is not accessible from the current context, an IllegalAccessException is thrown.
If the value cannot be converted to the field type via a widening conversion, an IllegalArgumentException is thrown.
object - the object to accessvalue - the new valueNullPointerException - if the object is null and the field is non-staticIllegalArgumentException - if the object is not compatible with the declaring classIllegalAccessException - if this field is not accessiblepublic String toString()
The format of the string is:
For example: public static java.io.InputStream
java.lang.System.in