”;
Introduction
The java.lang.reflect.Field class provides information about, and dynamic access to, a single field of a class or an interface. The reflected field may be a class (static) field or an instance field. A Field permits widening conversions to occur during a get or set access operation, but throws an IllegalArgumentException if a narrowing conversion would occur.
Class declaration
Following is the declaration for java.lang.reflect.Field class −
public final class Field extends AccessibleObject implements Member
Class methods
Sr.No. | Method & Description |
---|---|
1 | boolean equals(Object obj)
Compares this Field against the specified object. |
2 | Object get(Object obj)
Returns the value of the field represented by this Field, on the specified object. |
3 | <T extends Annotation> T getAnnotation(Class<T> annotationClass)
Returns this element”s annotation for the specified type if such an annotation is present, else null. |
4 | boolean getBoolean(Object obj)
Gets the value of a static or instance boolean field. |
5 | byte getByte(Object obj)
Gets the value of a static or instance byte field. |
6 | char getChar(Object obj)
Gets the value of a static or instance field of type char or of another primitive type convertible to type char via a widening conversion. |
7 | Annotation[] getDeclaredAnnotations()
Returns all annotations that are directly present on this element. |
8 | Class<?> getDeclaringClass()
Returns the Class object representing the class or interface that declares the field represented by this Field object. |
9 | double getDouble(Object obj)
Gets the value of a static or instance field of type double or of another primitive type convertible to type double via a widening conversion. |
10 | float getFloat(Object obj)
Gets the value of a static or instance field of type float or of another primitive type convertible to type float via a widening conversion. |
11 | Type getGenericType()
Returns a Type object that represents the declared type for the field represented by this Field object. |
12 | int getInt(Object obj)
Gets the value of a static or instance field of type int or of another primitive type convertible to type int via a widening conversion. |
13 | long getLong(Object obj)
Gets the value of a static or instance field of type long or of another primitive type convertible to type long via a widening conversion. |
14 | int getModifiers()
Returns the Java language modifiers for the field represented by this Field object, as an integer. |
15 | String getName()
RReturns the name of the field represented by this Field object. |
16 | short getShort(Object obj)
Gets the value of a static or instance field of type short or of another primitive type convertible to type short via a widening conversion. |
17 | Class<?> getType()
Returns a Class object that identifies the declared type for the field represented by this Field object. |
18 | int hashCode()
Returns a hashcode for this Field. |
19 | boolean isEnumConstant()
Returns true if this field represents an element of an enumerated type; returns false otherwise. |
20 | boolean isSynthetic()
This method returns true if the field represented by the current object is synthetic, else it returns false. |
21 | void setBoolean(Object obj, boolean z)
Sets the value of a field as a boolean on the specified object. |
22 | void setByte(Object obj, byte b)
Sets the value of a field as a byte on the specified object. |
23 | void setChar(Object obj, char c)
Sets the value of a field as a char on the specified object. |
24 | void setDouble(Object obj, double d)
Sets the value of a field as a double on the specified object. |
25 | void setFloat(Object obj, float f)
Sets the value of a field as a float on the specified object. |
26 | void setInt(Object obj, int i)
Sets the value of a field as an int on the specified object. |
27 | void setLong(Object obj, long l)
Sets the value of a field as a long on the specified object. |
28 | void setShort(Object obj, short s)
Sets the value of a field as a short on the specified object. |
29 | String toGenericString()
Returns a string describing this Field, including its generic type. |
30 | String toString()
Returns a string describing this Field. |
Methods inherited
This class inherits methods from the following classes −
- java.lang.reflect.AccessibleObject
- java.lang.Object
”;