java.lang.reflect – Error

java.lang.reflect – Error ”; Previous Next Introduction The java.lang.reflect Error contains the error which can occur during reflection operations. Errors Summary Sr.No. Error & Description 1 GenericSignatureFormatError Thrown when a syntactically malformed signature attribute is encountered by a reflective method that needs to interpret the generic signature information for a type, method or constructor. Print Page Previous Next Advertisements ”;

java.lang.reflect – Field

java.lang.reflect – Field Class ”; Previous Next 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 Print Page Previous Next Advertisements ”;

java.lang.reflect – Array

java.lang.reflect – Array Class ”; Previous Next Introduction The java.lang.reflect.Array class provides static methods to dynamically create and access Java arrays. Array permits widening conversions to occur during a get or set operation, but throws an IllegalArgumentException if a narrowing conversion would occur. Class declaration Following is the declaration for java.lang.reflect.Array class − public final class Array extends Object Class methods Sr.No. Method & Description 1 static Object get(Object array, int index) Returns the value of the indexed component in the specified array object. 2 static boolean getBoolean(Object array, int index) Returns the value of the indexed component in the specified array object, as a boolean. 3 static byte getByte(Object array, int index) Returns the value of the indexed component in the specified array object, as a byte. 4 static char getChar(Object array, int index) Returns the value of the indexed component in the specified array object, as a char. 5 static double getDouble(Object array, int index) Returns the value of the indexed component in the specified array object, as a double. 6 static float getFloat(Object array, int index) Returns the value of the indexed component in the specified array object, as a float. 7 static int getInt(Object array, int index) Returns the value of the indexed component in the specified array object, as an int. 8 static int getLength(Object array) Returns the length of the specified array object, as an int. 9 static long getLong(Object array, int index) Returns the value of the indexed component in the specified array object, as a long. 10 static short getShort(Object array, int index) Returns the value of the indexed component in the specified array object, as a short. 11 static Object newInstance(Class<?> componentType, int… dimensions) Creates a new array with the specified component type and dimensions. 12 static Object newInstance(Class<?> componentType, int length) Creates a new array with the specified component type and length. 13 static void set(Object array, int index, Object value) Sets the value of the indexed component of the specified array object to the specified new value. 14 static void setBoolean(Object array, int index, boolean z) Sets the value of the indexed component of the specified array object to the specified boolean value. 15 static void setByte(Object array, int index, byte b) Sets the value of the indexed component of the specified array object to the specified byte value. 16 static void setChar(Object array, int index, char c) Sets the value of the indexed component of the specified array object to the specified char value. 17 static void setDouble(Object array, int index, double d) Sets the value of the indexed component of the specified array object to the specified double value. 18 static void setFloat(Object array, int index, float f) Sets the value of the indexed component of the specified array object to the specified float value. 19 static void setInt(Object array, int index, int i) Sets the value of the indexed component of the specified array object to the specified int value. 20 static void setLong(Object array, int index, long l) Sets the value of the indexed component of the specified array object to the specified long value. 21 static void setShort(Object array, int index, short s) Sets the value of the indexed component of the specified array object to the specified short value. Methods inherited This class inherits methods from the following classes − java.lang.Object Print Page Previous Next Advertisements ”;

java.lang.reflect – Home

java.lang.reflect package tutorial Quick Guide Resources Job Search Discussion java.lang.reflect package provides classes and interfaces which are used to obtain reflective information about classes and objects. Reflection API allows programmatic access to information about the fields, methods and constructors of loaded classes. It allows use of reflected fields, methods, and constructors to operate on their underlying counterparts, within security restrictions. This reference will take you through simple and practical methods available in java.lang.reflect package. Audience This reference has been prepared for the beginners to help them understand the basic functionality related to all the methods available in java.lang.reflect package. Prerequisites Before you start doing practice with various types of examples given in this reference, I”m making an assumption that you are already aware of basic Java Programming. Print Page Previous Next Advertisements ”;