Field

                                               
    java.lang.Object                                          
     |                                         
     |--java.lang.reflect.AccessibleObject                                      
         |                                     
         |--java.lang.reflect.Field                                  
                                               

A Field provides information about a field of a class or an interface.

Get the field modifiers, name and type

ReturnMethodSummary
intgetModifiers()Returns the Java language modifiers for the field.
StringgetName()Returns the name of the field.
Class<?>getType()Returns a Class object that identifies the declared type.

Is this field an Enum, is it Synthetic

ReturnMethodSummary
booleanisEnumConstant()Returns true if this field represents an element of an enumerated type; returns false otherwise.
booleanisSynthetic()Returns true if this field is a synthetic field; returns false otherwise.

Get annotation for this field

ReturnMethodSummary
<T extends Annotation>T getAnnotation(Class<T> annotationClass) Returns this element's annotation.
Annotation[]getDeclaredAnnotations()Returns all annotations that are directly present on this element.

Get the class for this field

ReturnMethodSummary
Class<?>getDeclaringClass()Returns the Class object representing the class or interface that declares the field.

Get field value with Reflection

ReturnMethodSummary
Objectget(Object obj)Returns field value
booleangetBoolean(Object obj)Gets field value as boolean.
bytegetByte(Object obj)Gets field value as byte.
chargetChar(Object obj)Gets field value as char.
doublegetDouble(Object obj)Gets field value as double.
floatgetFloat(Object obj)Gets field value as float.
TypegetGenericType()Returns a Type object that represents the declared type for the field represented by this Field object.
intgetInt(Object obj)Gets field value as int.
longgetLong(Object obj)Gets field value as long.
shortgetShort(Object obj)Gets field value as short.

Set field value with Reflection

ReturnMethodSummary
voidset(Object obj, Object value)Sets the field value.
voidsetBoolean(Object obj, boolean z)Sets boolean field value.
voidsetByte(Object obj, byte b)Sets byte field value.
voidsetChar(Object obj, char c)Sets char field value.
voidsetDouble(Object obj, double d)Sets double field value.
voidsetFloat(Object obj, float f)Sets float field value.
voidsetInt(Object obj, int i)Sets int field value.
voidsetLong(Object obj, long l)Sets long field value.
voidsetShort(Object obj, short s)Sets short field value.

Get the string representation of a field

ReturnMethodSummary
StringtoGenericString()Returns a string describing this Field, including its generic type.
StringtoString()Returns a string describing this Field.
Revised from Open JDK source code
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.