Easy learning with example program codes

java reflection class

The java.lang.Class provides the methods to examine the runtime properties of the object including its members and type information. For every type of object, the JVM instantiates an immutable instance of java.lang.Class. Using reflection, we can get the metadata of a class at run time.


Commonly used methods of java.lang.Class class


Method Description
getName() It returns the class name
forName(String className) It loads the class and returns the reference of Class class.
newInstance() It creates new instance.
isInterface() It checks if it is interface.
isArray() It checks if it is array.
isPrimitive() It checks if it is primitive.
getSuperclass() It returns the superclass class reference.
getDeclaredFields() It returns the total number of fields of this class.
getDeclaredMethods() It returns the total number of methods of this class.
getDeclaredConstructors() It returns the total number of constructors of this class.
getDeclaredMethod(String name,Class[] parameterTypes) It returns the method class instance.


Copyright © 2018 CodesJava Protection Status SiteMap