# Class Class<T>

java.lang.Object
java.lang.Class<T>

All Implemented Interfaces:
  `Type`

public final class Class<T> extends Object implements Type
Instances of the class Class represent classes and interfaces in a running Java application. 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. Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes are loaded. The following example uses a Class object to print the class name of an object: Since: JDK1.0, CLDC 1.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Class()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Class`
  `asSubclass(Class superclass)`
  Replacement for Class.asSubclass(Class).
  `Object`
  `cast(Object object)`
  Replacement for Class.cast(Object).
  `boolean`
  `desiredAssertionStatus()`

  ###### Deprecated

  `static Class`
  `forName(java.lang.String className)`
  Returns the Class object associated with the class with the given string name.
  `<T extends java.lang.annotation.Annotation>
  T`
  `getAnnotation(Class annotationType)`
  Returns this element's annotation for the specified type if such an annotation is present, else null.
  `java.lang.annotation.Annotation[]`
  `getAnnotations()`
  Returns all annotations present on this element.
  `java.lang.String`
  `getCanonicalName()`

  ###### Deprecated

  `ClassLoader`
  `getClassLoader()`
  `Class`
  `getComponentType()`
  Gets for Array classes, this returns the type of the elements of the array.
  `java.lang.annotation.Annotation[]`
  `getDeclaredAnnotations()`
  Returns all annotations that are directly present on this element.
  `Constructor`
  `getEnclosingConstructor()`
  Returns null always.
  `Method`
  `getEnclosingMethod()`

  ###### Deprecated

  `Type[]`
  `getGenericInterfaces()`

  ###### Deprecated

  `java.lang.String`
  `getName()`
  Returns the fully-qualified name of the entity (class, interface, array class, primitive type, or void) represented by this Class object, as a String.
  `InputStream`
  `getResourceAsStream(java.lang.String name)`
  Finds a resource with a given name in the application's JAR file.
  `java.lang.String`
  `getSimpleName()`

  ###### Deprecated

  `boolean`
  `isAnnotation()`
  `boolean`
  `isAnnotationPresent(Class annotationType)`
  Returns true if an annotation for the specified type is present on this element, else false.
  `boolean`
  `isAnonymousClass()`
  replacement for Class.isAnonymousClass()
  `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.
  `boolean`
  `isEnum()`
  Replacement for Class.isEnum().
  `boolean`
  `isInstance(Object obj)`
  Determines if the specified Object is assignment-compatible with the object represented by this Class.
  `boolean`
  `isInterface()`
  Determines if the specified Class object represents an interface type.
  `boolean`
  `isLocalClass()`

  ###### Deprecated

  `boolean`
  `isPrimitive()`
  Returns true if this class is a primitive type.
  `boolean`
  `isRecord()`
  `boolean`
  `isSynthetic()`
  replacement for Class.isSynthetic()
  `Object`
  `newInstance()`
  Creates a new instance of a class.
  `java.lang.String`
  `toString()`
  Converts the object to a string.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### Class

    public Class()

- ## Method Details

  - ### getClassLoader

    public ClassLoader getClassLoader()

  - ### forName

    public static Class forName(java.lang.String className) throws java.lang.ClassNotFoundException

    Returns the Class object associated with the class with the given string name. Given the fully-qualified name for a class or interface, this method attempts to locate, load and link the class. For example, the following code fragment returns the runtime Class descriptor for the class named java.lang.Thread: Classt= Class.forName("java.lang.Thread")

    ###### Deprecated

    don't use this method for anything important since class names are obfuscated on the device!

    Throws:
      `java.lang.ClassNotFoundException`

  - ### getName

    public java.lang.String getName()

    Returns the fully-qualified 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 class of arrays, then the internal form of the name consists of the name of the element type in Java signature format, preceded by one or more "[" characters representing the depth of array nesting. Thus: (new Object[3]).getClass().getName() returns "[Ljava.lang.Object;" and: (new int[3][4][5][6][7][8][9]).getClass().getName() returns "[[[[[[[I". The encoding of element type names is as follows: B byte C char D double F float I int J long L class or interface S short Z boolean The class or interface name is given in fully qualified form as shown in the example above.

    ###### Deprecated

    don't use this method for anything important since class names are obfuscated on the device!

  - ### getResourceAsStream

    public InputStream getResourceAsStream(java.lang.String name)
    Finds a resource with a given name in the application's JAR file. This method returns null if no resource with this name is found in the application's JAR file. The resource names can be represented in two different formats: absolute or relative. Absolute format: /packagePathName/resourceName Relative format: resourceName In the absolute format, the programmer provides a fully qualified name that includes both the full path and the name of the resource inside the JAR file. In the path names, the character "/" is used as the separator. In the relative format, the programmer provides only the name of the actual resource. Relative names are converted to absolute names by the system by prepending the resource name with the fully qualified package name of class upon which the getResourceAsStream method was called.

  - ### isArray

    public boolean isArray()
    Determines if this Class object represents an array class.

  - ### isAssignableFrom

    public 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 a primitive type, this method returns true if the specified Class parameter is exactly this Class object; otherwise it returns false. Specifically, this method tests whether the type represented by the specified Class parameter can be converted to the type represented by this Class object via an identity conversion or via a widening reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.

  - ### isInstance

    public 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 type represented by this Class object without raising a ClassCastException. It returns false otherwise. Specifically, if this Class object represents a declared class, this method returns true if the specified Object argument is an instance of the represented class (or of any of its subclasses); it returns false otherwise. If this Class object represents an array class, this method returns true if the specified Object argument can be converted to an object of the array class by an identity conversion or by a widening reference conversion; it returns false otherwise. If this Class object represents an interface, this method returns true if the class or any superclass of the specified Object argument implements this interface; it returns false otherwise. If this Class object represents a primitive type, this method returns false.

  - ### isInterface

    public boolean isInterface()
    Determines if the specified Class object represents an interface type.

  - ### newInstance

    public Object newInstance() throws java.lang.InstantiationException, IllegalAccessException
    Creates a new instance of a class.
    Throws:
      `java.lang.InstantiationException`
      `IllegalAccessException`

  - ### toString

    public java.lang.String 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 the primitive type. If this Class object represents void this method returns "void".
    Overrides:
      `toString` in class `Object`

  - ### isAnnotation

    public boolean isAnnotation()

  - ### getAnnotation

    public <T extends java.lang.annotation.Annotation> T getAnnotation(Class annotationType)
    Returns this element's annotation for the specified type if such an annotation is present, else null.

  - ### getAnnotations

    public java.lang.annotation.Annotation[] getAnnotations()
    Returns all annotations present on this element.

  - ### getDeclaredAnnotations

    public java.lang.annotation.Annotation[] getDeclaredAnnotations()
    Returns all annotations that are directly present on this element.

  - ### isAnnotationPresent

    public boolean isAnnotationPresent(Class annotationType)
    Returns true if an annotation for the specified type is present on this element, else false.

  - ### asSubclass

    public Class asSubclass(Class superclass)

    Replacement for Class.asSubclass(Class).

    ###### Parameters

    - `c`: a Class

    - `superclass`: another Class which must be a superclass of c

    ###### Returns

    c

    ###### Throws

    - `java.lang.ClassCastException`: if c is

  - ### cast

    public Object cast(Object object)

    Replacement for Class.cast(Object). Throws a ClassCastException if obj is not an instance of class c, or a subtype of c.

    ###### Parameters

    - `c`: Class we want to cast obj to

    - `object`: object we want to cast

    ###### Returns

    Returns:

      The object, or `null` if the object is `null`.

      ###### Throws

      - `java.lang.ClassCastException`: @throws java.lang.ClassCastException if obj is not `null` or an instance of c

  - ### isEnum

    public boolean isEnum()

    Replacement for Class.isEnum().

    ###### Parameters

    - `class_`: class we want to test.

    ###### Returns

    true if the class was declared as an Enum.

  - ### isAnonymousClass

    public boolean isAnonymousClass()
    replacement for Class.isAnonymousClass()

  - ### getSimpleName

    public java.lang.String getSimpleName()

    ###### Deprecated

    don't use this method for anything important since class names are obfuscated on the device!

  - ### isSynthetic

    public boolean isSynthetic()
    replacement for Class.isSynthetic()

  - ### getCanonicalName

    public java.lang.String getCanonicalName()

    ###### Deprecated

    don't use this method for anything important since class names are obfuscated on the device!

  - ### getComponentType

    public Class getComponentType()
    Gets for Array classes, this returns the type of the elements of the array.

  - ### desiredAssertionStatus

    public boolean desiredAssertionStatus()

    ###### Deprecated

    Not supported

  - ### getGenericInterfaces

    public Type[] getGenericInterfaces()

    ###### Deprecated

    Not supported

  - ### isPrimitive

    public boolean isPrimitive()
    Returns true if this class is a primitive type.

  - ### getEnclosingMethod

    public Method getEnclosingMethod()

    ###### Deprecated

    Not supported

  - ### getEnclosingConstructor

    public Constructor getEnclosingConstructor()

    Returns null always. Not supported in CN1.

    ###### Deprecated

    Not supported

  - ### isLocalClass

    public boolean isLocalClass()

    ###### Deprecated

    Not supported

  - ### isRecord

    public boolean isRecord()