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 object)
Indicates whether or not the specified
object is equal to 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 field.
|
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.
|
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 field.
|
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, setAccessible
public static final Comparator<Field> ORDER_BY_NAME_AND_DECLARING_CLASS
public boolean isSynthetic()
isSynthetic
in interface Member
true
if this field is synthetic, false
otherwisepublic String toGenericString()
public boolean isEnumConstant()
true
if this field is an enumeration constant, false
otherwisepublic 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()
AnnotatedElement
getDeclaredAnnotations
in interface AnnotatedElement
getDeclaredAnnotations
in class AccessibleObject
public <A extends Annotation> A getAnnotation(Class<A> annotationType)
AnnotatedElement
null
if no annotation with the specified type is present
(including inherited annotations).getAnnotation
in interface AnnotatedElement
getAnnotation
in class AccessibleObject
annotationType
- the type of the annotation to search fornull
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
AnnotatedElement
isAnnotationPresent
in interface AnnotatedElement
isAnnotationPresent
in class AccessibleObject
annotationType
- the type of the annotation to search fortrue
if the annotation exists, false
otherwisepublic boolean equals(Object object)
object
is equal to this
field. To be equal, the specified object must be an instance of
Field
with the same declaring class, type and name as this field.equals
in class Object
object
- the object to comparetrue
if the specified object is equal to this method,
false
otherwisehashCode()
public 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 Class<?> getDeclaringClass()
getDeclaringClass
in interface Member
public 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 int getModifiers()
Modifier
class should
be used to decode the result.getModifiers
in interface Member
Modifier
public String getName()
public 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 Class<?> getType()
Class
associated with the type of this field.public int hashCode()
The hash code for a Field is the exclusive-or combination of the hash code of the field's name and the hash code of the name of its declaring class.
hashCode
in class Object
equals(java.lang.Object)
public 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