1 *java.lang.reflect.Field* *Field* A Field provides information about, and dynami
3 public final class Field
4 extends |java.lang.reflect.AccessibleObject|
5 implements |java.lang.reflect.Member|
7 |java.lang.reflect.Field_Description|
8 |java.lang.reflect.Field_Fields|
9 |java.lang.reflect.Field_Constructors|
10 |java.lang.reflect.Field_Methods|
12 ================================================================================
14 *java.lang.reflect.Field_Methods*
15 |java.lang.reflect.Field.equals(Object)|Compares this Field against the specifi
16 |java.lang.reflect.Field.get(Object)|Returns the value of the field represented
17 |java.lang.reflect.Field.getAnnotation(Class)|
18 |java.lang.reflect.Field.getBoolean(Object)|Gets the value of a static or insta
19 |java.lang.reflect.Field.getByte(Object)|Gets the value of a static or instance
20 |java.lang.reflect.Field.getChar(Object)|Gets the value of a static or instance
21 |java.lang.reflect.Field.getDeclaredAnnotations()|
22 |java.lang.reflect.Field.getDeclaringClass()|Returns the Class object represent
23 |java.lang.reflect.Field.getDouble(Object)|Gets the value of a static or instan
24 |java.lang.reflect.Field.getFloat(Object)|Gets the value of a static or instanc
25 |java.lang.reflect.Field.getGenericType()|Returns a Type object that represents
26 |java.lang.reflect.Field.getInt(Object)|Gets the value of a static or instance
27 |java.lang.reflect.Field.getLong(Object)|Gets the value of a static or instance
28 |java.lang.reflect.Field.getModifiers()|Returns the Java language modifiers for
29 |java.lang.reflect.Field.getName()|Returns the name of the field represented by
30 |java.lang.reflect.Field.getShort(Object)|Gets the value of a static or instanc
31 |java.lang.reflect.Field.getType()|Returns a Class object that identifies the
32 |java.lang.reflect.Field.hashCode()|Returns a hashcode for this Field.
33 |java.lang.reflect.Field.isEnumConstant()|Returns true if this field represents
34 |java.lang.reflect.Field.isSynthetic()|Returns true if this field is a syntheti
35 |java.lang.reflect.Field.set(Object,Object)|Sets the field represented by this
36 |java.lang.reflect.Field.setBoolean(Object,boolean)|Sets the value of a field a
37 |java.lang.reflect.Field.setByte(Object,byte)|Sets the value of a field as a by
38 |java.lang.reflect.Field.setChar(Object,char)|Sets the value of a field as a ch
39 |java.lang.reflect.Field.setDouble(Object,double)|Sets the value of a field as
40 |java.lang.reflect.Field.setFloat(Object,float)|Sets the value of a field as a
41 |java.lang.reflect.Field.setInt(Object,int)|Sets the value of a field as an int
42 |java.lang.reflect.Field.setLong(Object,long)|Sets the value of a field as a lo
43 |java.lang.reflect.Field.setShort(Object,short)|Sets the value of a field as a
44 |java.lang.reflect.Field.toGenericString()|Returns a string describing this Fie
45 |java.lang.reflect.Field.toString()|Returns a string describing this Field.
47 *java.lang.reflect.Field_Description*
49 A Field provides information about, and dynamic access to, a single field of a
50 class or an interface. The reflected field may be a class (static) field or an
53 A Field permits widening conversions to occur during a get or set access
54 operation, but throws an IllegalArgumentException if a narrowing conversion
58 *java.lang.reflect.Field.equals(Object)*
60 public boolean equals(java.lang.Object obj)
62 Compares this Field against the specified object. Returns true if the objects
63 are the same. Two Field objects are the same if they were declared by the same
64 class and have the same name and type.
67 *java.lang.reflect.Field.get(Object)*
69 public |java.lang.Object| get(java.lang.Object obj)
70 throws |java.lang.IllegalAccessException|
71 |java.lang.IllegalArgumentException|
73 Returns the value of the field represented by this Field, on the specified
74 object. The value is automatically wrapped in an object if it has a primitive
77 The underlying field's value is obtained as follows:
79 If the underlying field is a static field, the obj argument is ignored; it may
82 Otherwise, the underlying field is an instance field. If the specified obj
83 argument is null, the method throws a NullPointerException. If the specified
84 object is not an instance of the class or interface declaring the underlying
85 field, the method throws an IllegalArgumentException.
87 If this Field object enforces Java language access control, and the underlying
88 field is inaccessible, the method throws an IllegalAccessException. If the
89 underlying field is static, the class that declared the field is initialized if
90 it has not already been initialized.
92 Otherwise, the value is retrieved from the underlying instance or static field.
93 If the field has a primitive type, the value is wrapped in an object before
94 being returned, otherwise it is returned as is.
96 If the field is hidden in the type of obj, the field's value is obtained
97 according to the preceding rules.
99 obj - object from which the represented field's value is to be extracted
101 Returns: the value of the represented field in object obj; primitive values are wrapped
102 in an appropriate object before being returned
103 *java.lang.reflect.Field.getAnnotation(Class)*
105 public |java.lang.annotation.Annotation| getAnnotation(java.lang.Class annotationClass)
110 *java.lang.reflect.Field.getBoolean(Object)*
112 public boolean getBoolean(java.lang.Object obj)
113 throws |java.lang.IllegalAccessException|
114 |java.lang.IllegalArgumentException|
116 Gets the value of a static or instance boolean field.
118 obj - the object to extract the boolean value from
120 Returns: the value of the boolean field
121 *java.lang.reflect.Field.getByte(Object)*
123 public byte getByte(java.lang.Object obj)
124 throws |java.lang.IllegalAccessException|
125 |java.lang.IllegalArgumentException|
127 Gets the value of a static or instance byte field.
129 obj - the object to extract the byte value from
131 Returns: the value of the byte field
132 *java.lang.reflect.Field.getChar(Object)*
134 public char getChar(java.lang.Object obj)
135 throws |java.lang.IllegalAccessException|
136 |java.lang.IllegalArgumentException|
138 Gets the value of a static or instance field of type char or of another
139 primitive type convertible to type char via a widening conversion.
141 obj - the object to extract the char value from
143 Returns: the value of the field converted to type char
144 *java.lang.reflect.Field.getDeclaredAnnotations()*
146 public |java.lang.annotation.Annotation| getDeclaredAnnotations()
151 *java.lang.reflect.Field.getDeclaringClass()*
153 public |java.lang.Class| getDeclaringClass()
155 Returns the Class object representing the class or interface that declares the
156 field represented by this Field object.
159 *java.lang.reflect.Field.getDouble(Object)*
161 public double getDouble(java.lang.Object obj)
162 throws |java.lang.IllegalAccessException|
163 |java.lang.IllegalArgumentException|
165 Gets the value of a static or instance field of type double or of another
166 primitive type convertible to type double via a widening conversion.
168 obj - the object to extract the double value from
170 Returns: the value of the field converted to type double
171 *java.lang.reflect.Field.getFloat(Object)*
173 public float getFloat(java.lang.Object obj)
174 throws |java.lang.IllegalAccessException|
175 |java.lang.IllegalArgumentException|
177 Gets the value of a static or instance field of type float or of another
178 primitive type convertible to type float via a widening conversion.
180 obj - the object to extract the float value from
182 Returns: the value of the field converted to type float
183 *java.lang.reflect.Field.getGenericType()*
185 public |java.lang.reflect.Type| getGenericType()
187 Returns a Type object that represents the declared type for the field
188 represented by this Field object.
190 If the Type is a parameterized type, the Type object returned must accurately
191 reflect the actual type parameters used in the source code.
193 If an the type of the underlying field is a type variable or a parameterized
194 type, it is created. Otherwise, it is resolved.
197 Returns: a Type object that represents the declared type for the field represented by
199 *java.lang.reflect.Field.getInt(Object)*
201 public int getInt(java.lang.Object obj)
202 throws |java.lang.IllegalAccessException|
203 |java.lang.IllegalArgumentException|
205 Gets the value of a static or instance field of type int or of another
206 primitive type convertible to type int via a widening conversion.
208 obj - the object to extract the int value from
210 Returns: the value of the field converted to type int
211 *java.lang.reflect.Field.getLong(Object)*
213 public long getLong(java.lang.Object obj)
214 throws |java.lang.IllegalAccessException|
215 |java.lang.IllegalArgumentException|
217 Gets the value of a static or instance field of type long or of another
218 primitive type convertible to type long via a widening conversion.
220 obj - the object to extract the long value from
222 Returns: the value of the field converted to type long
223 *java.lang.reflect.Field.getModifiers()*
225 public int getModifiers()
227 Returns the Java language modifiers for the field represented by this Field
228 object, as an integer. The Modifier class should be used to decode the
232 *java.lang.reflect.Field.getName()*
234 public |java.lang.String| getName()
236 Returns the name of the field represented by this Field object.
239 *java.lang.reflect.Field.getShort(Object)*
241 public short getShort(java.lang.Object obj)
242 throws |java.lang.IllegalAccessException|
243 |java.lang.IllegalArgumentException|
245 Gets the value of a static or instance field of type short or of another
246 primitive type convertible to type short via a widening conversion.
248 obj - the object to extract the short value from
250 Returns: the value of the field converted to type short
251 *java.lang.reflect.Field.getType()*
253 public |java.lang.Class| getType()
255 Returns a Class object that identifies the declared type for the field
256 represented by this Field object.
259 Returns: a Class object identifying the declared type of the field represented by this
261 *java.lang.reflect.Field.hashCode()*
263 public int hashCode()
265 Returns a hashcode for this Field. This is computed as the exclusive-or of the
266 hashcodes for the underlying field's declaring class name and its name.
269 *java.lang.reflect.Field.isEnumConstant()*
271 public boolean isEnumConstant()
273 Returns true if this field represents an element of an enumerated type; returns
277 Returns: true if and only if this field represents an element of an enumerated type.
278 *java.lang.reflect.Field.isSynthetic()*
280 public boolean isSynthetic()
282 Returns true if this field is a synthetic field; returns false otherwise.
285 Returns: true if and only if this field is a synthetic field as defined by the Java
286 Language Specification.
287 *java.lang.reflect.Field.set(Object,Object)*
290 java.lang.Object obj,
291 java.lang.Object value)
292 throws |java.lang.IllegalAccessException|
293 |java.lang.IllegalArgumentException|
295 Sets the field represented by this Field object on the specified object
296 argument to the specified new value. The new value is automatically unwrapped
297 if the underlying field has a primitive type.
299 The operation proceeds as follows:
301 If the underlying field is static, the obj argument is ignored; it may be null.
303 Otherwise the underlying field is an instance field. If the specified object
304 argument is null, the method throws a NullPointerException. If the specified
305 object argument is not an instance of the class or interface declaring the
306 underlying field, the method throws an IllegalArgumentException.
308 If this Field object enforces Java language access control, and the underlying
309 field is inaccessible, the method throws an IllegalAccessException.
311 If the underlying field is final, the method throws an IllegalAccessException
312 unless setAccessible(true) has succeeded for this field and this field is
313 non-static. Setting a final field in this way is meaningful only during
314 deserialization or reconstruction of instances of classes with blank final
315 fields, before they are made available for access by other parts of a program.
316 Use in any other context may have unpredictable effects, including cases in
317 which other parts of a program continue to use the original value of this
320 If the underlying field is of a primitive type, an unwrapping conversion is
321 attempted to convert the new value to a value of a primitive type. If this
322 attempt fails, the method throws an IllegalArgumentException.
324 If, after possible unwrapping, the new value cannot be converted to the type of
325 the underlying field by an identity or widening conversion, the method throws
326 an IllegalArgumentException.
328 If the underlying field is static, the class that declared the field is
329 initialized if it has not already been initialized.
331 The field is set to the possibly unwrapped and widened new value.
333 If the field is hidden in the type of obj, the field's value is set according
334 to the preceding rules.
336 obj - the object whose field should be modified
337 value - the new value for the field of obj being modified
339 *java.lang.reflect.Field.setBoolean(Object,boolean)*
341 public void setBoolean(
342 java.lang.Object obj,
344 throws |java.lang.IllegalAccessException|
345 |java.lang.IllegalArgumentException|
347 Sets the value of a field as a boolean on the specified object. This method is
348 equivalent to set(obj, zObj), where zObj is a Boolean object and
349 zObj.booleanValue() == z.
351 obj - the object whose field should be modified
352 z - the new value for the field of obj being modified
354 *java.lang.reflect.Field.setByte(Object,byte)*
357 java.lang.Object obj,
359 throws |java.lang.IllegalAccessException|
360 |java.lang.IllegalArgumentException|
362 Sets the value of a field as a byte on the specified object. This method is
363 equivalent to set(obj, bObj), where bObj is a Byte object and bObj.byteValue()
366 obj - the object whose field should be modified
367 b - the new value for the field of obj being modified
369 *java.lang.reflect.Field.setChar(Object,char)*
372 java.lang.Object obj,
374 throws |java.lang.IllegalAccessException|
375 |java.lang.IllegalArgumentException|
377 Sets the value of a field as a char on the specified object. This method is
378 equivalent to set(obj, cObj), where cObj is a Character object and
379 cObj.charValue() == c.
381 obj - the object whose field should be modified
382 c - the new value for the field of obj being modified
384 *java.lang.reflect.Field.setDouble(Object,double)*
386 public void setDouble(
387 java.lang.Object obj,
389 throws |java.lang.IllegalAccessException|
390 |java.lang.IllegalArgumentException|
392 Sets the value of a field as a double on the specified object. This method is
393 equivalent to set(obj, dObj), where dObj is a Double object and
394 dObj.doubleValue() == d.
396 obj - the object whose field should be modified
397 d - the new value for the field of obj being modified
399 *java.lang.reflect.Field.setFloat(Object,float)*
401 public void setFloat(
402 java.lang.Object obj,
404 throws |java.lang.IllegalAccessException|
405 |java.lang.IllegalArgumentException|
407 Sets the value of a field as a float on the specified object. This method is
408 equivalent to set(obj, fObj), where fObj is a Float object and
409 fObj.floatValue() == f.
411 obj - the object whose field should be modified
412 f - the new value for the field of obj being modified
414 *java.lang.reflect.Field.setInt(Object,int)*
417 java.lang.Object obj,
419 throws |java.lang.IllegalAccessException|
420 |java.lang.IllegalArgumentException|
422 Sets the value of a field as an int on the specified object. This method is
423 equivalent to set(obj, iObj), where iObj is a Integer object and
424 iObj.intValue() == i.
426 obj - the object whose field should be modified
427 i - the new value for the field of obj being modified
429 *java.lang.reflect.Field.setLong(Object,long)*
432 java.lang.Object obj,
434 throws |java.lang.IllegalAccessException|
435 |java.lang.IllegalArgumentException|
437 Sets the value of a field as a long on the specified object. This method is
438 equivalent to set(obj, lObj), where lObj is a Long object and lObj.longValue()
441 obj - the object whose field should be modified
442 l - the new value for the field of obj being modified
444 *java.lang.reflect.Field.setShort(Object,short)*
446 public void setShort(
447 java.lang.Object obj,
449 throws |java.lang.IllegalAccessException|
450 |java.lang.IllegalArgumentException|
452 Sets the value of a field as a short on the specified object. This method is
453 equivalent to set(obj, sObj), where sObj is a Short object and
454 sObj.shortValue() == s.
456 obj - the object whose field should be modified
457 s - the new value for the field of obj being modified
459 *java.lang.reflect.Field.toGenericString()*
461 public |java.lang.String| toGenericString()
463 Returns a string describing this Field, including its generic type. The format
464 is the access modifiers for the field, if any, followed by the generic field
465 type, followed by a space, followed by the fully-qualified name of the class
466 declaring the field, followed by a period, followed by the name of the field.
468 The modifiers are placed in canonical order as specified by "The Java Language
469 Specification". This is public, protected or private first, and then other
470 modifiers in the following order: static, final, transient, volatile.
473 Returns: a string describing this Field, including its generic type
474 *java.lang.reflect.Field.toString()*
476 public |java.lang.String| toString()
478 Returns a string describing this Field. The format is the access modifiers for
479 the field, if any, followed by the field type, followed by a space, followed by
480 the fully-qualified name of the class declaring the field, followed by a
481 period, followed by the name of the field. For example:
483 public static final int java.lang.Thread.MIN_PRIORITY private int
484 java.io.FileDescriptor.fd
486 The modifiers are placed in canonical order as specified by "The Java Language
487 Specification". This is public, protected or private first, and then other
488 modifiers in the following order: static, final, transient, volatile.