Android
java.lang.reflect
public final class

java.lang.reflect.Field

java.lang.Object
java.lang.reflect.AccessibleObject AnnotatedElement
java.lang.reflect.Field Member

This class must be implemented by the VM vendor. This class models a field. Information about the field can be accessed, and the field's value can be accessed dynamically.

Summary

Constants inherited from interface java.lang.reflect.Member

Public Methods

          boolean  equals(Object object)
Compares the specified object to this Field and answer if they are equal.
          Object  get(Object object)
Return the value of the field in the specified object.
          boolean  getBoolean(Object object)
Return the value of the field in the specified object as a boolean.
          byte  getByte(Object object)
Return the value of the field in the specified object as a byte.
          char  getChar(Object object)
Return the value of the field in the specified object as a char.
          Annotation[]  getDeclaredAnnotations()
Gets all Annotations that are explicitly declared by this element (not inherited).
          Class<?>  getDeclaringClass()
Return the Class associated with the class that defined this field.
          double  getDouble(Object object)
Return the value of the field in the specified object as a double.
          float  getFloat(Object object)
Return the value of the field in the specified object as a float.
          Type  getGenericType()

Gets the declared type of this field.

          int  getInt(Object object)
Return the value of the field in the specified object as an int.
          long  getLong(Object object)
Return the value of the field in the specified object as a long.
          int  getModifiers()
Return the modifiers for the modeled field.
          String  getName()
Return the name of the modeled field.
          short  getShort(Object object)
Return 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 the receiver.
          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)
Set the value of the field in the specified object to the boolean value.
          void  setBoolean(Object object, boolean value)
Set the value of the field in the specified object to the boolean value.
          void  setByte(Object object, byte value)
Set the value of the field in the specified object to the byte value.
          void  setChar(Object object, char value)
Set the value of the field in the specified object to the char value.
          void  setDouble(Object object, double value)
Set the value of the field in the specified object to the double value.
          void  setFloat(Object object, float value)
Set 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)
Set the value of the field in the specified object to the long value.
          void  setShort(Object object, short value)
Set the value of the field in the specified object to the short value.
          String  toGenericString()

Returns the String representation of the field's declaration, including the type parameters.

          String  toString()
Returns a string containing a concise, human-readable description of the receiver.
Methods inherited from class java.lang.reflect.AccessibleObject
Methods inherited from class java.lang.Object
Methods inherited from interface java.lang.reflect.AnnotatedElement
Methods inherited from interface java.lang.reflect.Member

Details

Public Methods

public boolean equals(Object object)

Compares the specified object to this Field and answer if they are equal. The object must be an instance of Field with the same defining class and name.

Parameters

object the object to compare

Returns

  • true if the specified object is equal to this Field, false otherwise

See Also

public Object get(Object object)

Return the value of the field in the specified object. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

The value of the field is returned. If the type of this field is a base type, the field value is automatically wrapped.

Parameters

object the object to access

Returns

  • the field value, possibly wrapped

Throws

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 modeled field is not accessible

public boolean getBoolean(Object object)

Return the value of the field in the specified object as a boolean. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public byte getByte(Object object)

Return the value of the field in the specified object as a byte. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public char getChar(Object object)

Return the value of the field in the specified object as a char. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public Annotation[] getDeclaredAnnotations()

Gets all Annotations that are explicitly declared by this element (not inherited).

public Class<?> getDeclaringClass()

Return the Class associated with the class that defined this field.

Returns

  • the declaring class

public double getDouble(Object object)

Return the value of the field in the specified object as a double. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public float getFloat(Object object)

Return the value of the field in the specified object as a float. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public Type getGenericType()

Gets the declared type of this field.

Returns

  • An instance of Type.

Throws

GenericSignatureFormatError if the generic method signature is invalid.
TypeNotPresentException if the component type points to a missing type.
MalformedParameterizedTypeException if the component type points to a type that can't be instantiated for some reason.

public int getInt(Object object)

Return the value of the field in the specified object as an int. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public long getLong(Object object)

Return the value of the field in the specified object as a long. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public int getModifiers()

Return the modifiers for the modeled field. The Modifier class should be used to decode the result.

Returns

  • the modifiers

See Also

public String getName()

Return the name of the modeled field.

Returns

  • the name

public short getShort(Object object)

Return the value of the field in the specified object as a short. This reproduces the effect of object.fieldName

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

Parameters

object the object to access

Returns

  • the field value

Throws

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 modeled field is not accessible

public Class<?> getType()

Return the Class associated with the type of this field.

Returns

  • the type

public int hashCode()

Returns an integer hash code for the receiver. Objects which are equal answer the same value for this method.

The hash code for a Field is the hash code of the field's name.

Returns

  • the receiver's hash

See Also

public boolean isEnumConstant()

Indicates whether or not this field is an enumeration constant.

Returns

  • A value of true if this field is an enumeration constant, otherwise false.

public boolean isSynthetic()

Indicates whether or not this field is synthetic.

Returns

  • A value of true if this field is synthetic, otherwise false.

public void set(Object object, Object value)

Set the value of the field in the specified object to the boolean value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled field is not accessible from the current context, an IllegalAccessException is thrown.

If the field type is a base 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setBoolean(Object object, boolean value)

Set the value of the field in the specified object to the boolean value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setByte(Object object, byte value)

Set the value of the field in the specified object to the byte value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setChar(Object object, char value)

Set the value of the field in the specified object to the char value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setDouble(Object object, double value)

Set the value of the field in the specified object to the double value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setFloat(Object object, float value)

Set the value of the field in the specified object to the float value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setInt(Object object, int value)

Set the value of the field in the specified object to the int value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setLong(Object object, long value)

Set the value of the field in the specified object to the long value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public void setShort(Object object, short value)

Set the value of the field in the specified object to the short value. This reproduces the effect of object.fieldName = value

If the modeled 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 the modeled 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.

Parameters

object the object to access
value the new value

Throws

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 modeled field is not accessible

public String toGenericString()

Returns the String representation of the field's declaration, including the type parameters.

Returns

  • An instance of String.

public String toString()

Returns a string containing a concise, human-readable description of the receiver.

The format of the string is:

  • modifiers (if any)
  • return type
  • declaring class name
  • '.'
  • field name

For example: public static java.io.InputStream java.lang.System.in

Returns

  • a printable representation for the receiver
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48