Moyosoft Products | Services | Download | Contact us    
JavaDocPlus
Products  >  JavaDocPlus  >  Online demo    


Latest release




Get a FREE license !
(Special offer, time limited)

Review JavaDocPlus on your blog and we'll give you a free license.

Open source projects licenced under LGPL, EPL, ASL, BSD or MIT can also obtain a free license.

Contact us to check if your project/blog is eligible.

Online demo
JavaDocPlus Demo  |  Show in full page mode
   
Overview  |  
Classic JavaDoc

Class Class

java.lang.Objectjava.lang.Class

Implemented Interfaces:

public final class Class implements Serializable, GenericDeclaration, Type, AnnotatedElement

Instances of the class Class represent classes and interfaces in a running Java application. An enum is a kind of class and an annotation is a kind of interface. Every array also belongs to a class that is reflected as a Class object that is shared by all arrays with the same element type and 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.

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded and by calls to the defineClass method in the class loader.

The following example uses a Class object to print the class name of an object:

     void printClassName(Object obj) {
         System.out.println("The class of " + obj +
                            " is " + obj.getClass().getName());
     }
 

It is also possible to get the Class object for a named type (or for void) using a class literal (JLS Section 15.8.2). For example:

     System.out.println("The name of class Foo is: "+Foo.class.getName());
 

Author:
unascribed

Version:
1.135, 05/25/01

See Also:

Since:
JDK1.0

Methods

asSubclass (Class clazz)
Casts this Class object to represent a subclass of the class represented by the specified class object. Checks that that the cast is valid, and throws a ClassCastException if it is not. If this method succeeds, it always returns a reference to this class object. This method is usef ... more >
cast (Object obj)
Casts an object to the class or interface represented by this Class object.
boolean
desiredAssertionStatus ()
Returns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked. If this class has had its assertion status set, the most recent setting will be returned; otherwise, if any package default assertion status pertains to th ... more >
static Class
forName (String className)
Returns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to: Class.forName(className, true, currentLoader) where currentLoader denotes the defining class loader of the current class. For example, the f ... more >
static Class
forName (String name, boolean initialize, ClassLoader loader)
Returns the Class object associated with the class or interface with the given string name, using the given class loader. Given the fully qualified name for a class or interface (in the same format returned by getName) this method attempts to locate, load, and link the class or interfa ... more >
getAnnotation (Class annotationClass)
getAnnotations ()
getCanonicalName ()
Returns the canonical name of the the underlying class as defined by the Java Language Specification. Returns null if the underlying class does not have a canonical name (i.e., if it is a local or anonymous class or an array whose component type does not have a canonical name).
getClasses ()
Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. This includes public class and interface members inherited from superclasses and public class and interface members declared by ... more >
getClassLoader ()
Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader. If a security manager is present, and the caller's class l ... more >
getComponentType ()
Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null.
getConstructor (Class parameterTypes)
Returns a Constructor object that reflects the specified public constructor of the class represented by this Class object. The parameterTypes parameter is an array of Class objects that identify the constructor's formal parameter types, in declared order. The constructor to reflect ... more >
getConstructors ()
Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. An array of length 0 is returned if the class has no public constructors, or if the class is an array class, or if the class reflects a primitive type or void.
getDeclaredAnnotations ()
getDeclaredClasses ()
Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. This includes public, protected, default (package) access, and private classes and interfaces declared by the class, but excludes inherited cla ... more >
getDeclaredConstructor (Class parameterTypes)
Returns a Constructor object that reflects the specified constructor of the class or interface represented by this Class object. The parameterTypes parameter is an array of Class objects that identify the constructor's formal parameter types, in declared order.
getDeclaredConstructors ()
Returns an array of Constructor objects reflecting all the constructors declared by the class represented by this Class object. These are public, protected, default (package) access, and private constructors. The elements in the array returned are not sorted and are not in any particu ... more >
getDeclaredField (String name)
Returns a Field object that reflects the specified declared field of the class or interface represented by this Class object. The name parameter is a String that specifies the simple name of the desired field. Note that this method will not reflect the length field of an array class.
getDeclaredFields ()
Returns an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields. The elements in the array returned are not sort ... more >
getDeclaredMethod (String name, Class parameterTypes)
Returns a Method object that reflects the specified declared method of the class or interface represented by this Class object. The name parameter is a String that specifies the simple name of the desired method, and the parameterTypes parameter is an array of Class objects that ident ... more >
getDeclaredMethods ()
Returns an array of Method objects reflecting all the methods declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private methods, but excludes inherited methods. The elements in the array returned are not ... more >
getDeclaringClass ()
If the class or interface represented by this Class object is a member of another class, returns the Class object representing the class in which it was declared. This method returns null if this class or interface is not a member of any other class. If this Class object represents a ... more >
getEnclosingClass ()
Returns the immediately enclosing class of the underlying class. If the underlying class is a top level class this method returns null.
getEnclosingConstructor ()
If this Class object represents a local or anonymous class within a constructor, returns a Constructor object representing the immediately enclosing constructor of the underlying class. Returns null otherwise. In particular, this method returns null if the underlying class is a local ... more >
getEnclosingMethod ()
If this Class object represents a local or anonymous class within a method, returns a Method object representing the immediately enclosing method of the underlying class. Returns null otherwise. In particular, this method returns null if the underlying class is a local or anonymous c ... more >
getEnumConstants ()
Returns the elements of this enum class or null if this Class object does not represent an enum type.
getField (String name)
Returns a Field object that reflects the specified public member field of the class or interface represented by this Class object. The name parameter is a String specifying the simple name of the desired field. The field to be reflected is determined by the algorithm that follows. ... more >
getFields ()
Returns an array containing Field objects reflecting all the accessible public fields of the class or interface represented by this Class object. The elements in the array returned are not sorted and are not in any particular order. This method returns an array of length 0 if the cla ... more >
getGenericInterfaces ()
Returns the Types representing the interfaces directly implemented by the class or interface represented by this object. If a superinterface is a parameterized type, the Type object returned for it must accurately reflect the actual type parameters used in the source code. The par ... more >
getGenericSuperclass ()
Returns the Type representing the direct superclass of the entity (class, interface, primitive type or void) represented by this Class. If the superclass is a parameterized type, the Type object returned must accurately reflect the actual type parameters used in the source code. Th ... more >
getInterfaces ()
Determines the interfaces implemented by the class or interface represented by this object. If this object represents a class, the return value is an array containing objects representing all interfaces implemented by the class. The order of the interface objects in the array corres ... more >
getMethod (String name, Class parameterTypes)
Returns a Method object that reflects the specified public member method of the class or interface represented by this Class object. The name parameter is a String specifying the simple name the desired method. The parameterTypes parameter is an array of Class objects that identify th ... more >
getMethods ()
Returns an array containing Method objects reflecting all the public member 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. Array classes return all the (p ... more >
int
getModifiers ()
Returns the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants for public, protected, private, final, static, abstract and interface; they should be decoded using the methods of class Modifier. ... more >
getName ()
Returns the name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String. If this class object represents a reference type that is not an array type then the binary name of the class is returned, as specified by the Jav ... more >
getPackage ()
Gets the package for this class. The class loader of this class is used to find the package. If the class was loaded by the bootstrap class loader the set of packages loaded from CLASSPATH is searched to find the package of the class. Null is returned if no package object was created ... more >
...ecurity.ProtectionDomain
getProtectionDomain ()
Returns the ProtectionDomain of this class. If there is a security manager installed, this method first calls the security manager's checkPermission method with a RuntimePermission("getProtectionDomain") permission to ensure it's ok to get the ProtectionDomain.
getResource (String name)
Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to Cl ... more >
getResourceAsStream (String name)
Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to Cl ... more >
getSigners ()
Gets the signers of this class.
getSimpleName ()
Returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous. The simple name of an array is the simple name of the component type with "[]" appended. In particular the simple name of an array whose compon ... more >
getSuperclass ()
Returns the Class representing the superclass of the entity (class, interface, primitive type or void) represented by this Class. If this Class represents either the Object class, an interface, a primitive type, or void, then null is returned. If this object represents an array class ... more >
getTypeParameters ()
Returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order. Returns an array of length 0 if the underlying generic declaration declares no type variables.
boolean
isAnnotation ()
Returns true if this Class object represents an annotation type. Note that if this method returns true, #isInterface() would also return true, as all annotation types are also interfaces.
boolean
isAnnotationPresent (Class annotationClass)
boolean
isAnonymousClass ()
Returns true if and only if the underlying class is an anonymous class.
boolean
isArray ()
Determines if this Class object represents an array class.
boolean
isAssignableFrom (Class cls)
Determines if the class or interface represented by this Class object is either the same as, or is a superclass or superinterface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false. If this Class object represents ... more >
boolean
isEnum ()
Returns true if and only if this class was declared as an enum in the source code.
boolean
isInstance (Object obj)
Determines if the specified Object is assignment-compatible with the object represented by this Class. This method is the dynamic equivalent of the Java language instanceof operator. The method returns true if the specified Object argument is non-null and can be cast to the reference ... more >
boolean
isInterface ()
Determines if the specified Class object represents an interface type.
boolean
isLocalClass ()
Returns true if and only if the underlying class is a local class.
boolean
isMemberClass ()
Returns true if and only if the underlying class is a member class.
boolean
isPrimitive ()
Determines if the specified Class object represents a primitive type. There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely ... more >
boolean
isSynthetic ()
Returns true if this class is a synthetic class; returns false otherwise.
newInstance ()
Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized. Note that this method propagates any exception thrown by the null ... more >
toString ()
Converts the object to a string. The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName. If this Class object represents a primitive type, this method returns the name of ... more >

Inherited methods

Community comments



Powered by JavaDocPlus