Class Class<T>
- java.lang.Object
-
- java.lang.Class<T>
-
public final class Class<T> extends Object
The in-memory representation of a Java class. This representation serves as the starting point for querying class-related information, a process usually called "reflection". There are basically three types ofClass
instances: those representing real classes and interfaces, those representing primitive types, and those representing array classes.Class instances representing object types (classes or interfaces)
These represent an ordinary class or interface as found in the class hierarchy. The name associated with these
Class
instances is simply the fully qualified class name of the class or interface that it represents. In addition to this human-readable name, each class is also associated by a so-called signature, which is the letter "L", followed by the class name and a semicolon (";"). The signature is what the runtime system uses internally for identifying the class (for example in a DEX file).Classes representing primitive types
These represent the standard Java primitive types and hence share their names (for example "int" for the
int
primitive type). Although it is not possible to create new instances based on theseClass
instances, they are still useful for providing reflection information, and as the component type of array classes. There is oneClass
instance for each primitive type, and their signatures are:B
representing thebyte
primitive typeS
representing theshort
primitive typeI
representing theint
primitive typeJ
representing thelong
primitive typeF
representing thefloat
primitive typeD
representing thedouble
primitive typeC
representing thechar
primitive typeZ
representing theboolean
primitive typeV
representing void function return values
Classes representing array classes
These represent the classes of Java arrays. There is one such
Class
instance per combination of array leaf component type and arity (number of dimensions). In this case, the name associated with theClass
consists of one or more left square brackets (one per dimension in the array) followed by the signature of the class representing the leaf component type, which can be either an object type or a primitive type. The signature of aClass
representing an array type is the same as its name. Examples of array class signatures are:[I
representing theint[]
type[Ljava/lang/String;
representing theString[]
type[[[C
representing thechar[][][]
type (three dimensions!)
- Since:
- 1.0
-
-
Method Summary
Methods Modifier and Type Method and Description String
getName()
Returns the name of the class represented by thisClass
.T
newInstance()
Returns a new instance of the class represented by thisClass
, created by invoking the default (that is, zero-argument) constructor.
-
-
-
Method Detail
-
getName
public String getName()
Returns the name of the class represented by thisClass
. For a description of the format which is used, see the class definition ofClass
.- Returns:
- the name of the class represented by this
Class
.
-
newInstance
public T newInstance() throws IllegalAccessException, InstantiationException
Returns a new instance of the class represented by thisClass
, created by invoking the default (that is, zero-argument) constructor. If there is no such constructor, or if the creation fails (either because of a lack of available memory or because an exception is thrown by the constructor), anInstantiationException
is thrown. If the default constructor exists but is not accessible from the context where this method is invoked, anIllegalAccessException
is thrown.- Returns:
- a new instance of the class represented by this
Class
. - Throws:
IllegalAccessException
- if the default constructor is not visible.InstantiationException
- if the instance can not be created.
-
-