Fieldpublic final class Field extends AccessibleObject implements MemberThis class represents a field. Information about the field can be accessed,
and the field's value can be accessed dynamically. |
Fields Summary |
---|
private Class | declaringClass | private Class | type | private Type | genericType | private volatile boolean | genericTypesAreInitialized | private String | name | private int | slot | private static final int | TYPE_BOOLEAN | private static final int | TYPE_BYTE | private static final int | TYPE_CHAR | private static final int | TYPE_SHORT | private static final int | TYPE_INTEGER | private static final int | TYPE_FLOAT | private static final int | TYPE_LONG | private static final int | TYPE_DOUBLE |
Constructors Summary |
---|
Field(Field orig)Construct a clone of the given instance.
/*package*/
this(orig.declaringClass, orig.type, orig.name, orig.slot);
// Copy the accessible flag.
if (orig.flag) {
this.flag = true;
}
| private Field(Class declaringClass, Class type, String name, int slot)
this.declaringClass = declaringClass;
this.type = type;
this.name = name;
this.slot = slot;
|
Methods Summary |
---|
public boolean | equals(java.lang.Object object)Indicates whether or not the specified {@code object} is equal to this
field. To be equal, the specified object must be an instance of
{@code Field} with the same declaring class, type and name as this field.
return object instanceof Field && toString().equals(object.toString());
| public java.lang.Object | get(java.lang.Object object)Returns the value of the field in the specified object. This reproduces
the effect of {@code 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.
return getField(object, declaringClass, type, slot, flag);
| private native byte | getBField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| public boolean | getBoolean(java.lang.Object object)Returns the value of the field in the specified object as a {@code
boolean}. This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getZField(object, declaringClass, type, slot, flag, TYPE_BOOLEAN);
| public byte | getByte(java.lang.Object object)Returns the value of the field in the specified object as a {@code byte}.
This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getBField(object, declaringClass, type, slot, flag, TYPE_BYTE);
| private native char | getCField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| public char | getChar(java.lang.Object object)Returns the value of the field in the specified object as a {@code char}.
This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getCField(object, declaringClass, type, slot, flag, TYPE_CHAR);
| private native double | getDField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| public java.lang.annotation.Annotation[] | getDeclaredAnnotations()
return getDeclaredAnnotations(declaringClass, slot);
| private native java.lang.annotation.Annotation[] | getDeclaredAnnotations(java.lang.Class declaringClass, int slot)
| public java.lang.Class | getDeclaringClass()Returns the class that declares this field.
return declaringClass;
| public double | getDouble(java.lang.Object object)Returns the value of the field in the specified object as a {@code
double}. This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getDField(object, declaringClass, type, slot, flag, TYPE_DOUBLE);
| private native float | getFField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| private native java.lang.Object | getField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck)
| private native int | getFieldModifiers(java.lang.Class declaringClass, int slot)
| public float | getFloat(java.lang.Object object)Returns the value of the field in the specified object as a {@code float}
. This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getFField(object, declaringClass, type, slot, flag, TYPE_FLOAT);
| public java.lang.reflect.Type | getGenericType()Returns the generic type of this field.
initGenericType();
return Types.getType(genericType);
| private native int | getIField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| public int | getInt(java.lang.Object object)Returns the value of the field in the specified object as an {@code int}.
This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getIField(object, declaringClass, type, slot, flag, TYPE_INTEGER);
| private native long | getJField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| public long | getLong(java.lang.Object object)Returns the value of the field in the specified object as a {@code long}.
This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getJField(object, declaringClass, type, slot, flag, TYPE_LONG);
| public int | getModifiers()Returns the modifiers for this field. The {@link Modifier} class should
be used to decode the result.
return getFieldModifiers(declaringClass, slot);
| public java.lang.String | getName()Returns the name of this field.
return name;
| private native short | getSField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| public short | getShort(java.lang.Object object)Returns the value of the field in the specified object as a {@code short}
. This reproduces the effect of {@code object.fieldName}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
return getSField(object, declaringClass, type, slot, flag, TYPE_SHORT);
| private java.lang.String | getSignature()Returns the constructor's signature in non-printable form. This is called
(only) from IO native code and needed for deriving the serialVersionUID
of the class
return getSignature(type);
| private native java.lang.Object[] | getSignatureAnnotation(java.lang.Class declaringClass, int slot)Get the Signature annotation for this field. Returns null if not found.
| java.lang.String | getSignatureAttribute(){@inheritDoc}
Object[] annotation = getSignatureAnnotation(declaringClass, slot);
if (annotation == null) {
return null;
}
return StringUtils.combineStrings(annotation);
| public java.lang.Class | getType()Return the {@link Class} associated with the type of this field.
return type;
| private native boolean | getZField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no)
| 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.
// BEGIN android-changed
return name.hashCode() ^ getDeclaringClass().getName().hashCode();
// END android-changed
| private synchronized void | initGenericType()
if (!genericTypesAreInitialized) {
String signatureAttribute = getSignatureAttribute();
GenericSignatureParser parser = new GenericSignatureParser(
VMStack.getCallingClassLoader2());
parser.parseForField(this.declaringClass, signatureAttribute);
genericType = parser.fieldType;
if (genericType == null) {
genericType = getType();
}
genericTypesAreInitialized = true;
}
| public boolean | isEnumConstant()Indicates whether or not this field is an enumeration constant.
int flags = getFieldModifiers(declaringClass, slot);
return (flags & Modifier.ENUM) != 0;
| public boolean | isSynthetic()Indicates whether or not this field is synthetic.
int flags = getFieldModifiers(declaringClass, slot);
return (flags & Modifier.SYNTHETIC) != 0;
| public void | set(java.lang.Object object, java.lang.Object value)Sets the value of the field in the specified object to the value. This
reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setField(object, declaringClass, type, slot, flag, value);
| private native void | setBField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, byte b)
| public void | setBoolean(java.lang.Object object, boolean value)Sets the value of the field in the specified object to the {@code
boolean} value. This reproduces the effect of {@code object.fieldName =
value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setZField(object, declaringClass, type, slot, flag, TYPE_BOOLEAN, value);
| public void | setByte(java.lang.Object object, byte value)Sets the value of the field in the specified object to the {@code byte}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setBField(object, declaringClass, type, slot, flag, TYPE_BYTE, value);
| private native void | setCField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, char c)
| public void | setChar(java.lang.Object object, char value)Sets the value of the field in the specified object to the {@code char}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setCField(object, declaringClass, type, slot, flag, TYPE_CHAR, value);
| private native void | setDField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, double v)
| public void | setDouble(java.lang.Object object, double value)Sets the value of the field in the specified object to the {@code double}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setDField(object, declaringClass, type, slot, flag, TYPE_DOUBLE, value);
| private native void | setFField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, float f)
| private native void | setField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, java.lang.Object value)
| public void | setFloat(java.lang.Object object, float value)Sets the value of the field in the specified object to the {@code float}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setFField(object, declaringClass, type, slot, flag, TYPE_FLOAT, value);
| private native void | setIField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, int i)
| public void | setInt(java.lang.Object object, int value)Set the value of the field in the specified object to the {@code int}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setIField(object, declaringClass, type, slot, flag, TYPE_INTEGER, value);
| private native void | setJField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, long j)
| public void | setLong(java.lang.Object object, long value)Sets the value of the field in the specified object to the {@code long}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setJField(object, declaringClass, type, slot, flag, TYPE_LONG, value);
| private native void | setSField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, short s)
| public void | setShort(java.lang.Object object, short value)Sets the value of the field in the specified object to the {@code short}
value. This reproduces the effect of {@code object.fieldName = value}
If this field is static, the object argument is ignored.
Otherwise, if the object is {@code 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.
setSField(object, declaringClass, type, slot, flag, TYPE_SHORT, value);
| private native void | setZField(java.lang.Object o, java.lang.Class declaringClass, java.lang.Class type, int slot, boolean noAccessCheck, int type_no, boolean z)
| public java.lang.String | toGenericString()Returns the string representation of this field, including the field's
generic type.
StringBuilder sb = new StringBuilder(80);
// append modifiers if any
int modifier = getModifiers();
if (modifier != 0) {
sb.append(Modifier.toString(modifier)).append(' ");
}
// append generic type
appendGenericType(sb, getGenericType());
sb.append(' ");
// append full field name
sb.append(getDeclaringClass().getName()).append('.").append(getName());
return sb.toString();
| public java.lang.String | toString()Returns a string containing a concise, human-readable description of this
field.
The format of the string is:
- modifiers (if any)
- type
- declaring class name
- '.'
- field name
For example: {@code public static java.io.InputStream
java.lang.System.in}
StringBuffer result = new StringBuffer(Modifier.toString(getModifiers()));
if (result.length() != 0)
result.append(' ");
result.append(type.getName());
result.append(' ");
result.append(declaringClass.getName());
result.append('.");
result.append(name);
return result.toString();
|
|