Java.lang.Class Class
Java Class<T> Class
A Class class is included in the Java.lang package. In a running Java application, instances of the class Class represent classes and interfaces. There is no public function Object() for this class. Instead, when classes are loaded and calls to the defineClass function in the class loader, the Java Virtual Machine automatically constructs Class instances.
Class declaration
The declaration of java.lang.Class class is:
public final class Class<T> extends Object implements Serializable, GenericDeclaration, Type, AnnotatedElement
java.lang.Class Methods
The java.lang.Class class has a number of methods which are listed below:
Member Methods
S.N | Methods & Description |
---|---|
1. | String getCanonicalName() Returns the canonical name of the underlying class as defined by the Java Language Specification. |
2. | ClassLoader getClassLoader() Returns the class loader for the class. |
3. | Constructor<?>[] getConstructors() Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. |
4. | Constructor<?>[] getDeclaredConstructors() Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. |
5. | Field[] getDeclaredFields() Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. |
6. | Method[] getDeclaredMethods() Returns an array containing Method objects reflecting all the declared methods of the class or interface represented by this Class object, including public, protected, default (package) access, and private methods, but excluding inherited methods. |
7. | Field[] getFields() Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. |
8. | Type[] getGenericInterfaces() Returns the Types representing the interfaces directly implemented by the class or interface represented by this object. |
9. | Type getGenericSuperclass() Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class. |
10. | Method[] getMethods() Returns an array containing Method objects reflecting all the public methods of the class or interface represented by this Class object, including those declared by the class or interface and those inherited from superclasses and superinterfaces. |
11. | int getModifiers() Returns the Java language modifiers for this class or interface, encoded in an integer. |
12. | String getName() Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String. |
13. | Package getPackage() Gets the package for this class. |
14. | String getSimpleName() Returns the simple name of the underlying class as given in the source code. |
15. | String getTypeName() Return an informative string for the name of this type. |
16. | boolean isAnonymousClass() Returns true if and only if the underlying class is an anonymous class. |
17. | boolean isAnnotation() Returns true if this Class object represents an annotation type. |
18. | boolean isArray() Determines if this Class object represents an array class. |
19. | boolean isEnum() Returns true if and only if this class was declared as an enum in the source code. |
20. | boolean isInterface() Determines if the specified Class object represents an interface type. |
21. | boolean isLocalClass() Returns true if and only if the underlying class is a local class. |
22. | boolean isMemberClass() Returns true if and only if the underlying class is a member class. |
23. | boolean isPrimitive() Determines if the specified Class object represents a primitive type. |
24. | boolean isSynthetic() Returns true if this class is a synthetic class; returns false otherwise. |
25. | String toGenericString() Returns a string describing this Class, including information about modifiers and type parameters. |
26. | String toString() Converts the object to a string. |
Methods inherited
This class inherits the methods of the following class:
- java.lang.Object