java.lang.reflect.Field
java.lang.Object
None
java.lang.reflect.Member
New as of JDK 1.1
The Field class represents a variable or constant in a class. A Field object can be obtained by calling the getField() method of a Class object. Field includes methods for getting the name, modifiers, type, and declaring class of a field. The class also provides methods that can set and retrieve the value of a field for a particular object.
public final class java.lang.reflect.Field extends java.lang.Object implements java.lang.reflect.Member { // Instance Methods public boolean equals(Object obj); public native Object get(Object obj); public native boolean getBoolean(Object obj); public native byte getByte(Object obj); public native char getChar(Object obj); public Class getDeclaringClass(); public native double getDouble(Object obj); public native float getFloat(Object obj); public native int getInt(Object obj); public native long getLong(Object obj); public native int getModifiers(); public String getName(); public native short getShort(Object obj); public Class getType(); public int hashCode(); public native void set(Object obj, Object value); public native void setBoolean(Object obj, boolean z); public native void setByte(Object obj, byte b); public native void setChar(Object obj, char c); public native void setDouble(Object obj, double d); public native void setFloat(Object obj, float f); public native void setInt(Object obj, int i); public native void setLong(Object obj, long l); public native void setShort(Object obj, short s); public String toString(); }
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if obj is an instance of Field, and it is equivalent to this Field.
public native Object get(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The value of this field in the given object.
If obj is not the correct type.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field. If the field contains a value of a primitive type, the value is wrapped in an appropriate object, and the object is returned.
public native boolean getBoolean(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The boolean value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a boolean.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a boolean. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native byte getByte(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The byte value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a byte.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a byte. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native char getChar(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The char value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a char.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a char. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
The Class object that represents the class that declared this field.
Member.getDeclaringClass()
This method returns the Class object for the class in which this field is declared.
public native double getDouble(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The double value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a double.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a double. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native float getFloat(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The float value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a float.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a float. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native int getInt(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The int value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a int.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as an int. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native long getLong(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The long value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a long.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a long. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
An integer that represents the modifier keywords used to declare this field.
Member.getModifiers()
This method returns an integer value that represents the modifiers of this field. The Modifier class should decode the returned value.
The name of this field as a String.
Member.getName()
This method returns the name of this field.
public native short getShort(Object obj) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be retrieved.
The short value of this field in the given object.
If obj is not the correct type, or the field cannot be converted to a short.
If the field is not accessible.
If obj is null.
This method returns the value of this field in the given object as a short. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
The Class object that represents the type of this field.
This method returns the Class object for the type of this field.
A hashcode for this object.
Object.hashCode()
This method returns a hashcode for this Field.
public native void set(Object obj, Object value) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or value cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field. If the field contains a value of a primitive type, the given value is automatically unwrapped before it is used to set the value of the field.
public native void setBoolean(Object obj, boolean z) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or z cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given boolean value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or b cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given byte value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setChar(Object obj, char c) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or c cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given char value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or d cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given double value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or f cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given float value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or i cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given int value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or l cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given long value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
public native void setShort(Object obj, short s) throws IllegalArgumentException, IllegalAccessException
The instance whose field value is to be set.
The new value.
If obj is not an instance of the correct class, or s cannot be converted to the correct type.
If the field is not accessible or declared final.
If obj is null.
This method sets the value of this field in the given object to the given short value. If the field is declared static, the obj parameter is ignored. Otherwise, the object supplied must be an instance of the class that declares this field.
A string representation of this object.
Object.toString()
This method returns a string representation of this Field. This string contains the access modifiers of the field, if any, followed by the type, the fully qualified name of the declaring class, a period, and the name of the field.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
finalize() |
Object |
getClass() |
Object |
notify() |
Object |
notifyAll() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Class, Constructor, IllegalAccessException, IllegalArgumentException, Member, Method, Modifier, NullPointerException, Object