Intel

Developer Zone

Class

java.lang

Class 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 of Class 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 these Class instances, they are still useful for providing reflection information, and as the component type of array classes. There is one Class instance for each primitive type, and their signatures are:

    • B representing the byte primitive type
    • S representing the short primitive type
    • I representing the int primitive type
    • J representing the long primitive type
    • F representing the float primitive type
    • D representing the double primitive type
    • C representing the char primitive type
    • Z representing the boolean primitive type
    • V 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 the Class 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 a Class representing an array type is the same as its name. Examples of array class signatures are:

    • [I representing the int[] type
    • [Ljava/lang/String; representing the String[] type
    • [[[C representing the char[][][] 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 this Class.
      T newInstance()
      Returns a new instance of the class represented by this Class, created by invoking the default (that is, zero-argument) constructor.
    • Method Detail

      • getName

        public String getName()
        Returns the name of the class represented by this Class. For a description of the format which is used, see the class definition of Class.
        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 this Class, 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), an InstantiationException is thrown. If the default constructor exists but is not accessible from the context where this method is invoked, an IllegalAccessException 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.