Class in Java Set -3

java.lang.Class

Instances of the class Class represent classes and interfaces in a running Java application. An enum type and a record type are classes; an annotation type is a kind of interface. Every array also belongs to a class that is reflected as a Class object shared by all arrays with the same element type and a number of dimensions. The primitive Java types(boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects.

The class has no public constructor. Instead, a Class object is constructed automatically by the Java Virtual 

The machine when a class is derived from the bytes of a class file through the invocation of one of the following methods:

1. ClassLoader::defineClass.

2. java.lang.invoke.MethodHandles.Lookup::defineClass.

3 java.lang.invoke.MethodHandles.Lookup::defineHiddenClass

The methods of class Class expose many characteristics of a class or interface. Most characteristics are derived from the class file that the class loader passed to the Java Virtual Machine or from the class file passed to Lookup::defineClassor Lookup::defineHiddenClass.A few characteristics are determined by the class loading environment at run time, such as the module returned by getModule().

Implemented Interfaces:

Serializable

AnnotatedElement

GenericDeclaration

Type

Some methods of Class

getResource(String)This method finds a resource with a given name.

getResourceAsStream(String)This method finds a resource with a given name.

getSigners()This method gets the signers of this class.

getSimpleName()This method returns the simple name of the underlying class as given in the source code. 

getSuperclass()This method returns the Class representing the direct superclass of the entity (class, interface, primitive type, or void) represented by this Class.

getTypeName()This method returns an informative string for the name of this type.

getTypeParameters()This method returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order.

isAnnotation()This method returns true if this Class object represents an annotation type.

isAnnotationPresent(Class)This method returns true if an annotation for the specified type is present on this element, else false.

isAnonymousClass()This method returns true if and only if the underlying class is an anonymous class.

isArray()This method determines if this Class object represents an array class.

isAssignableFrom(Class)This method determines if the class or interface represented by this Class object is either the same as, or is a superclass or super interface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.

isEnum()This method returns true if and only if this class was declared as an enum in the source code.

isHidden()This method returns true if and only if the underlying class is a hidden class.

isInstance(Object)This method determines if the specified Object is assignment-compatible with the object represented by this Class.

isInterface()This method determines if this Class object represents an interface type.

isLocalClass()This method returns true if and only if the underlying class is a local class.

isMemberClass()This method returns true if and only if the underlying class is a member class.

isNestmateOf(Class)This method determines if the given Class is a nestmate of the class or interface represented by this Class object.

isPrimitive()This method determines if the specified Class object represents a primitive type.

isRecord()This method returns true if and only if this class is a record class.

isSealed()This method returns true if and only if this Class object represents a sealed class or interface.

isSynthetic()This method returns true if and only if this class has the synthetic modifier bit set.

permittedSubclasses()This method returns an array containing ClassDesc objects representing all the direct subclasses or direct implementation classes permitted to extend or implement this class or interface if it is sealed.

toGenericString()This method returns a string describing this Class, including information about modifiers and type parameters.

toString()This method converts the object to a string. The string representation is the string "class" or "interface", followed by a space, and then by the name of the class in the format returned by getName.


Class in Java Set -1

Class in Java Set -2

Class in Java Set -3

No comments:

Post a Comment