Field(示例,出错代码)

java.lang.reflect
类 Field
java.lang.Object
java.lang.reflect.AccessibleObject
java.lang.reflect.Field
所有已实现的接口:
AnnotatedElement, Member
public final class Field
extends AccessibleObject
implements Member
This class represents a field. Information about the field can be accessed, and the field's value can be accessed dynamically.


从以下版本开始:
Android 1.0
字段摘要

从接口 java.lang.reflect.Member 继承的字段
DECLARED, PUBLIC

方法摘要
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.
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 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.

从类 java.lang.reflect.AccessibleObject 继承的方法
getAnnotation, getAnnotations, isAccessible, isAnnotationPresent, setAccessible, setAccessible

从类 java.lang.Object 继承的方法
getClass, notify, notifyAll, wait, wait, wait

方法详细信息
isSynthetic
public boolean isSynthetic()
Indicates whether or not this field is synthetic.
指定者:
接口 Member 中的 isSynthetic
返回:
true if this field is synthetic, false otherwise
从以下版本开始:
Android 1.0
toGenericString
public String toGenericString()
Returns the string representation of this field, including the field's generic type.
返回:
the string representation of this field
从以下版本开始:
Android 1.0
isEnumConstant
public boolean isEnumConstant()
Indicates whether or not this field is an enumeration constant.
返回:
true if this field is an enumeration constant, false otherwise
从以下版本开始:
Android 1.0
getGenericType
public Type getGenericType()
Returns the generic type of this field.
返回:
the generic type
抛出:
GenericSignatureFormatError - if the generic field signature is invalid
TypeNotPresentException - if the generic type points to a missing type
MalformedParameterizedTypeException - if the generic type points to a type that cannot be instantiated for some reason
从以下版本开始:
Android 1.0
getDeclaredAnnotations
public Annotation[] getDeclaredAnnotations()
从接口 AnnotatedElement 复制的描述
Returns, for this element, all annotations that are explicitly declared (not inherited). If there are no declared annotations present, this method returns a zero length array.
指定者:
接口 AnnotatedElement 中的 getDeclaredAnnotations
覆盖:
类 AccessibleObject 中的 getDeclaredAnnotations
返回:
an array of annotations declared for this element
equals
public boolean equals(Object object)
Indicates whether or not the specified 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.
覆盖:
类 Object 中的 equals
参数:
object - the object to compare
返回:
true if the specified object is equal to this method, false otherwise
从以下版本开始:
Android 1.0
另请参见:
hashCode()
get
public Object get(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object. This reproduces the effect of object.fieldName
If the type of this field is a primitive type, the field value is automatically wrapped.


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 access
返回:
the field value, possibly wrapped
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getBoolean
public boolean getBoolean(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getByte
public byte getByte(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getChar
public char getChar(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getDeclaringClass
public Class<?> getDeclaringClass()
Returns the class that declares this field.
指定者:
接口 Member 中的 getDeclaringClass
返回:
the declaring class
从以下版本开始:
Android 1.0
getDouble
public double getDouble(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getFloat
public float getFloat(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getInt
public int getInt(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as an 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getLong
public long getLong(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getModifiers
public int getModifiers()
Returns the modifiers for this field. The Modifier class should be used to decode the result.
指定者:
接口 Member 中的 getModifiers
返回:
the modifiers for this field
从以下版本开始:
Android 1.0
另请参见:
Modifier
getName
public String getName()
Returns the name of this field.
指定者:
接口 Member 中的 getName
返回:
the name of this field
从以下版本开始:
Android 1.0
getShort
public short getShort(Object object)
throws IllegalAccessException,
IllegalArgumentException
Returns the value of the field in the specified object as a 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 access
返回:
the field value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
getType
public Class<?> getType()
Return the Class associated with the type of this field.
返回:
the type of this field
从以下版本开始:
Android 1.0
hashCode
public int hashCode()
Returns an integer hash code for this field. Objects which are equal return the same value for this method.
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.


覆盖:
类 Object 中的 hashCode
返回:
the hash code for this field
从以下版本开始:
Android 1.0
另请参见:
equals(java.lang.Object)
set
public void set(Object object,
Object value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 field type is a primitive type, the value is automatically unwrapped. If the unwrap 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setBoolean
public void setBoolean(Object object,
boolean value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setByte
public void setByte(Object object,
byte value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setChar
public void setChar(Object object,
char value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setDouble
public void setDouble(Object object,
double value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setFloat
public void setFloat(Object object,
float value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setInt
public void setInt(Object object,
int value)
throws IllegalAccessException,
IllegalArgumentException
Set the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setLong
public void setLong(Object object,
long value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
setShort
public void setShort(Object object,
short value)
throws IllegalAccessException,
IllegalArgumentException
Sets the value of the field in the specified object to the 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 access
value - the new value
抛出:
NullPointerException - if the object is null and the field is non-static
IllegalArgumentException - if the object is not compatible with the declaring class
IllegalAccessException - if this field is not accessible
从以下版本开始:
Android 1.0
toString
public String toString()
Returns a string containing a concise, human-readable description of thisfield.
The format of the string is:


modifiers (if any)
type
declaring class name
'.'
field name
For example: public static java.io.InputStreamjava.lang.System.in


覆盖:
类 Object 中的 toString
返回:
a printable representation for this field
从以下版本开始:
Android 1.0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值