# Interface ClassType

All Superinterfaces:
  `Accessible, Comparable<ReferenceType>, Mirror, ReferenceType, Type`

public interface ClassType extends ReferenceType
A mirror of a class in the target VM. A ClassType is a refinement of `ReferenceType` that applies to true classes in the JLS sense of the definition (not an interface, not an array type). Any `ObjectReference` that mirrors an instance of such a class will have a ClassType as its type.

Since:
  1.3
See Also:
  - `ObjectReference`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `INVOKE_SINGLE_THREADED`
  Perform method invocation with only the invoking thread resumed

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<InterfaceType>`
  `allInterfaces()`
  Gets the interfaces directly and indirectly implemented by this class.
  `Method`
  `concreteMethodByName(String name, String signature)`
  Returns a single non-abstract `Method` visible from this class that has the given name and signature.
  `List<InterfaceType>`
  `interfaces()`
  Gets the interfaces directly implemented by this class.
  `Value`
  `invokeMethod(ThreadReference thread, Method method, List<? extends Value> arguments, int options)`
  Invokes the specified static `Method` in the target VM.
  `boolean`
  `isEnum()`
  Determine if this class was declared as an enum.
  `ObjectReference`
  `newInstance(ThreadReference thread, Method method, List<? extends Value> arguments, int options)`
  Constructs a new instance of this type, using the given constructor `Method` in the target VM.
  `void`
  `setValue(Field field, Value value)`
  Assigns a value to a static field.
  `List<ClassType>`
  `subclasses()`
  Gets the currently loaded, direct subclasses of this class.
  `ClassType`
  `superclass()`
  Gets the superclass of this class.

  ### Methods declared in interface Accessible

  `isPackagePrivate, isPrivate, isProtected, isPublic, modifiers`
  Modifier and Type
  Method
  Description
  `boolean`
  `isPackagePrivate()`
  Determines if this object mirrors a package private item.
  `boolean`
  `isPrivate()`
  Determines if this object mirrors a private item.
  `boolean`
  `isProtected()`
  Determines if this object mirrors a protected item.
  `boolean`
  `isPublic()`
  Determines if this object mirrors a public item.
  `int`
  `modifiers()`
  Returns the Java programming language modifiers, encoded in an integer.

  ### Methods declared in interface Comparable

  `compareTo`
  Modifier and Type
  Method
  Description
  `int`
  `compareTo(ReferenceType o)`
  Compares this object with the specified object for order.

  ### Methods declared in interface Mirror

  `toString, virtualMachine`
  Modifier and Type
  Method
  Description
  `String`
  `toString()`
  Returns a String describing this mirror
  `VirtualMachine`
  `virtualMachine()`
  Gets the VirtualMachine to which this Mirror belongs.

  ### Methods declared in interface ReferenceType

  `allFields, allLineLocations, allLineLocations, allMethods, availableStrata, classLoader, classObject, constantPool, constantPoolCount, defaultStratum, equals, failedToInitialize, fieldByName, fields, genericSignature, getValue, getValues, hashCode, instances, isAbstract, isFinal, isInitialized, isPrepared, isStatic, isVerified, locationsOfLine, locationsOfLine, majorVersion, methods, methodsByName, methodsByName, minorVersion, module, name, nestedTypes, sourceDebugExtension, sourceName, sourceNames, sourcePaths, visibleFields, visibleMethods`
  Modifier and Type
  Method
  Description
  `List<Field>`
  `allFields()`
  Returns a list containing each `Field` declared in this type, and its superclasses, implemented interfaces, and/or superinterfaces.
  `List<Location>`
  `allLineLocations()`
  Returns a list containing a `Location` object for each executable source line in this reference type.
  `List<Location>`
  `allLineLocations(String stratum, String sourceName)`
  Returns a list containing a `Location` object for each executable source line in this reference type.
  `List<Method>`
  `allMethods()`
  Returns a list containing each `Method` declared in this type, and its superclasses, implemented interfaces, and/or superinterfaces.
  `List<String>`
  `availableStrata()`
  Return the available strata for this reference type.
  `ClassLoaderReference`
  `classLoader()`
  Gets the classloader object which loaded the class corresponding to this type.
  `ClassObjectReference`
  `classObject()`
  Returns the class object that corresponds to this type in the target VM.
  `byte[]`
  `constantPool()`
  Returns the raw bytes of the constant pool in the format of the constant_pool item of the Class File Format in the Java Virtual Machine Specification.
  `int`
  `constantPoolCount()`
  Returns the number of entries in the constant pool plus one.
  `String`
  `defaultStratum()`
  Returns the default stratum for this reference type.
  `boolean`
  `equals(Object obj)`
  Compares the specified Object with this ReferenceType for equality.
  `boolean`
  `failedToInitialize()`
  Determines if initialization failed for this class.
  `Field`
  `fieldByName(String fieldName)`
  Finds the visible `Field` with the given non-ambiguous name.
  `List<Field>`
  `fields()`
  Returns a list containing each `Field` declared in this type.
  `String`
  `genericSignature()`
  Gets the generic signature for this type if there is one.
  `Value`
  `getValue(Field field)`
  Gets the `Value` of a given static `Field` in this type.
  `Map<Field,Value>`
  `getValues(List<? extends Field> fields)`
  Returns a map containing the `Value` of each static `Field` in the given list.
  `int`
  `hashCode()`
  Returns the hash code value for this ObjectReference.
  `List<ObjectReference>`
  `instances(long maxInstances)`
  Returns instances of this ReferenceType.
  `boolean`
  `isAbstract()`
  Determines if this type was declared abstract.
  `boolean`
  `isFinal()`
  Determines if this type was declared final.
  `boolean`
  `isInitialized()`
  Determines if this type has been initialized.
  `boolean`
  `isPrepared()`
  Determines if this type has been prepared.
  `boolean`
  `isStatic()`
  Determines if this type was declared static.
  `boolean`
  `isVerified()`
  Determines if this type has been verified.
  `List<Location>`
  `locationsOfLine(int lineNumber)`
  Returns a List containing all `Location` objects that map to the given line number.
  `List<Location>`
  `locationsOfLine(String stratum, String sourceName, int lineNumber)`
  Returns a List containing all `Location` objects that map to the given line number.
  `int`
  `majorVersion()`
  Returns the class major version number, as defined in the class file format of the Java Virtual Machine Specification.
  `List<Method>`
  `methods()`
  Returns a list containing each `Method` declared directly in this type.
  `List<Method>`
  `methodsByName(String name)`
  Returns a List containing each visible `Method` that has the given name.
  `List<Method>`
  `methodsByName(String name, String signature)`
  Returns a List containing each visible `Method` that has the given name and signature.
  `int`
  `minorVersion()`
  Returns the class minor version number, as defined in the class file format of the Java Virtual Machine Specification.
  `default ModuleReference`
  `module()`
  Gets the module object which contains the class corresponding to this type.
  `String`
  `name()`
  Returns the name of this `ReferenceType` object.
  `List<ReferenceType>`
  `nestedTypes()`
  Returns a List containing `ReferenceType` objects that are declared within this type and are currently loaded into the Virtual Machine.
  `String`
  `sourceDebugExtension()`
  Get the source debug extension of this type.
  `String`
  `sourceName()`
  Gets an identifying name for the source corresponding to the declaration of this type.
  `List<String>`
  `sourceNames(String stratum)`
  Gets the identifying names for all the source corresponding to the declaration of this type.
  `List<String>`
  `sourcePaths(String stratum)`
  Gets the paths to the source corresponding to the declaration of this type.
  `List<Field>`
  `visibleFields()`
  Returns a list containing each unhidden and unambiguous `Field` in this type.
  `List<Method>`
  `visibleMethods()`
  Returns a list containing each `Method` declared or inherited by this type.

  ### Methods declared in interface Type

  `signature`
  Modifier and Type
  Method
  Description
  `String`
  `signature()`
  Returns the type signature for this type.

- ## Field Details

  - ### INVOKE_SINGLE_THREADED

    static final int INVOKE_SINGLE_THREADED
    Perform method invocation with only the invoking thread resumed
    See Also:
      - Constant Field Values

- ## Method Details

  - ### superclass

    ClassType superclass()
    Gets the superclass of this class.
    Returns:
      a `ClassType` that mirrors the superclass of this class in the target VM. If no such class exists, returns null

  - ### interfaces

    List<InterfaceType> interfaces()
    Gets the interfaces directly implemented by this class. Only the interfaces that are declared with the "implements" keyword in this class are included.
    Returns:
      a List of `InterfaceType` objects each mirroring a direct interface this ClassType in the target VM. If none exist, returns a zero length List.
    Throws:
      `ClassNotPreparedException` - if this class not yet been prepared.

  - ### allInterfaces

    List<InterfaceType> allInterfaces()
    Gets the interfaces directly and indirectly implemented by this class. Interfaces returned by `interfaces()` are returned as well all superinterfaces.
    Returns:
      a List of `InterfaceType` objects each mirroring an interface of this ClassType in the target VM. If none exist, returns a zero length List.
    Throws:
      `ClassNotPreparedException` - if this class not yet been prepared.

  - ### subclasses

    List<ClassType> subclasses()
    Gets the currently loaded, direct subclasses of this class. No ordering of this list is guaranteed.
    Returns:
      a List of `ClassType` objects each mirroring a loaded subclass of this class in the target VM. If no such classes exist, this method returns a zero-length list.

  - ### isEnum

    boolean isEnum()
    Determine if this class was declared as an enum.
    Returns:
      `true` if this class was declared as an enum; false otherwise.

  - ### setValue

    void setValue(Field field, Value value) throws InvalidTypeException, ClassNotLoadedException
    Assigns a value to a static field. The `Field` must be valid for this ClassType; that is, it must be from the mirrored object's class or a superclass of that class. The field must not be final.

    Object values must be assignment compatible with the field type (This implies that the field type must be loaded through the enclosing class' class loader). Primitive values must be either assignment compatible with the field type or must be convertible to the field type without loss of information. See JLS section 5.2 for more information on assignment compatibility.

    Parameters:
      `field` - the field to set.
      `value` - the value to be assigned.
    Throws:
      `IllegalArgumentException` - if the field is not static, the field is final, or the field does not exist in this class.
      `ClassNotLoadedException` - if the field type has not yet been loaded through the appropriate class loader.
      `InvalidTypeException` - if the value's type does not match the field's declared type.
      `VMCannotBeModifiedException` - if the VirtualMachine is read-only - see `VirtualMachine.canBeModified()`.

  - ### invokeMethod

    Value invokeMethod(ThreadReference thread, Method method, List<? extends Value> arguments, int options) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException
    Invokes the specified static `Method` in the target VM. The specified method can be defined in this class, or in a superclass. The method must be a static method but not a static initializer. Use `newInstance(ThreadReference, Method, List, int)` to create a new object and run its constructor.

    The method invocation will occur in the specified thread. Method invocation can occur only if the specified thread has been suspended by an event which occurred in that thread. Method invocation is not supported when the target VM has been suspended through `VirtualMachine.suspend()` or when the specified thread is suspended through `ThreadReference.suspend()`.

    The specified method is invoked with the arguments in the specified argument list. The method invocation is synchronous; this method does not return until the invoked method returns in the target VM. If the invoked method throws an exception, this method will throw an `InvocationException` which contains a mirror to the exception object thrown.

    Object arguments must be assignment compatible with the argument type (This implies that the argument type must be loaded through the enclosing class' class loader). Primitive arguments must be either assignment compatible with the argument type or must be convertible to the argument type without loss of information. If the method being called accepts a variable number of arguments, then the last argument type is an array of some component type. The argument in the matching position can be omitted, or can be null, an array of the same component type, or an argument of the component type followed by any number of other arguments of the same type. If the argument is omitted, then a 0 length array of the component type is passed. The component type can be a primitive type. Autoboxing is not supported. See Section 5.2 of The Java Language Specification for more information on assignment compatibility.

    By default, all threads in the target VM are resumed while the method is being invoked if they were previously suspended by an event or by `VirtualMachine.suspend()` or `ThreadReference.suspend()`. This is done to prevent the deadlocks that will occur if any of the threads own resources, such as monitors, that will be needed by the invoked method. Note, however, that this implicit resume acts exactly like `ThreadReference.resume()`, so if the thread's suspend count is greater than 1, it will remain in a suspended state during the invocation and thus a deadlock could still occur. By default, when the invocation completes, all threads in the target VM are suspended, regardless their state before the invocation. It is possible that breakpoints or other events might occur during the invocation. This can cause deadlocks as described above. It can also cause a deadlock if invokeMethod is called from the client's event handler thread. In this case, this thread will be waiting for the invokeMethod to complete and won't read the EventSet that comes in for the new event. If this new EventSet is SUSPEND_ALL, then a deadlock will occur because no one will resume the EventSet. To avoid this, all EventRequests should be disabled before doing the invokeMethod, or the invokeMethod should not be done from the client's event handler thread.

    The resumption of other threads during the invocation can be prevented by specifying the `INVOKE_SINGLE_THREADED` bit flag in the `options` argument; however, there is no protection against or recovery from the deadlocks described above, so this option should be used with great caution. Only the specified thread will be resumed (as described for all threads above). Upon completion of a single threaded invoke, the invoking thread will be suspended once again. Note that any threads started during the single threaded invocation will not be suspended when the invocation completes.

    If the target VM is disconnected during the invoke (for example, through `VirtualMachine.dispose()`) the method invocation continues.

    API Note:
      Virtual threads are typically user-mode threads scheduled by the Java runtime rather than the operating system. As such, there may be more cases with virtual threads where the `INVOKE_SINGLE_THREADED` option may cause a deadlock. For example, suspending all threads in the target VM may suspend threads that support the timer mechanism for virtual threads, and thus methods such as `Thread.sleep(long)` may deadlock.
    Parameters:
      `thread` - the thread in which to invoke.
      `method` - the `Method` to invoke.
      `arguments` - the list of `Value` arguments bound to the invoked method. Values from the list are assigned to arguments in the order they appear in the method signature.
      `options` - the integer bit flag options.
    Returns:
      a `Value` mirror of the invoked method's return value.
    Throws:
      `IllegalArgumentException` - if the method is not a member of this class or a superclass, if the size of the argument list does not match the number of declared arguments for the method, or if the method is an initializer, constructor or static initializer.
      `ClassNotLoadedException` - if any argument type has not yet been loaded through the appropriate class loader.
      `IncompatibleThreadStateException` - if the specified thread has not been suspended by an event.
      `InvocationException` - if the method invocation resulted in an exception in the target VM.
      `InvalidTypeException` - If the arguments do not meet this requirement -- Object arguments must be assignment compatible with the argument type. This implies that the argument type must be loaded through the enclosing class' class loader. Primitive arguments must be either assignment compatible with the argument type or must be convertible to the argument type without loss of information. See JLS section 5.2 for more information on assignment compatibility.
      `VMCannotBeModifiedException` - if the VirtualMachine is read-only - see `VirtualMachine.canBeModified()`.

  - ### newInstance

    ObjectReference newInstance(ThreadReference thread, Method method, List<? extends Value> arguments, int options) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException
    Constructs a new instance of this type, using the given constructor `Method` in the target VM. The specified constructor must be defined in this class.

    Instance creation will occur in the specified thread. Instance creation can occur only if the specified thread has been suspended by an event which occurred in that thread. Instance creation is not supported when the target VM has been suspended through `VirtualMachine.suspend()` or when the specified thread is suspended through `ThreadReference.suspend()`.

    The specified constructor is invoked with the arguments in the specified argument list. The invocation is synchronous; this method does not return until the constructor returns in the target VM. If the invoked method throws an exception, this method will throw an `InvocationException` which contains a mirror to the exception object thrown.

    Object arguments must be assignment compatible with the argument type (This implies that the argument type must be loaded through the enclosing class' class loader). Primitive arguments must be either assignment compatible with the argument type or must be convertible to the argument type without loss of information. If the method being called accepts a variable number of arguments, then the last argument type is an array of some component type. The argument in the matching position can be omitted, or can be null, an array of the same component type, or an argument of the component type, followed by any number of other arguments of the same type. If the argument is omitted, then a 0 length array of the component type is passed. The component type can be a primitive type. Autoboxing is not supported. See section 5.2 of The Java Language Specification for more information on assignment compatibility.

    By default, all threads in the target VM are resumed while the method is being invoked if they were previously suspended by an event or by `VirtualMachine.suspend()` or `ThreadReference.suspend()`. This is done to prevent the deadlocks that will occur if any of the threads own resources, such as monitors, that will be needed by the invoked method. It is possible that breakpoints or other events might occur during the invocation. Note, however, that this implicit resume acts exactly like `ThreadReference.resume()`, so if the thread's suspend count is greater than 1, it will remain in a suspended state during the invocation. By default, when the invocation completes, all threads in the target VM are suspended, regardless their state before the invocation.

    The resumption of other threads during the invocation can be prevented by specifying the `INVOKE_SINGLE_THREADED` bit flag in the `options` argument; however, there is no protection against or recovery from the deadlocks described above, so this option should be used with great caution. Only the specified thread will be resumed (as described for all threads above). Upon completion of a single threaded invoke, the invoking thread will be suspended once again. Note that any threads started during the single threaded invocation will not be suspended when the invocation completes.

    If the target VM is disconnected during the invoke (for example, through `VirtualMachine.dispose()`) the method invocation continues.

    API Note:
      Virtual threads are typically user-mode threads scheduled by the Java runtime rather than the operating system. As such, there may be more cases with virtual threads where the `INVOKE_SINGLE_THREADED` option may cause a deadlock. For example, suspending all threads in the target VM may suspend threads that support the timer mechanism for virtual threads, and thus methods such as `Thread.sleep(long)` may deadlock.
    Parameters:
      `thread` - the thread in which to invoke.
      `method` - the constructor `Method` to invoke.
      `arguments` - the list of `Value` arguments bound to the invoked constructor. Values from the list are assigned to arguments in the order they appear in the constructor signature.
      `options` - the integer bit flag options.
    Returns:
      an `ObjectReference` mirror of the newly created object.
    Throws:
      `IllegalArgumentException` - if the method is not a member of this class, if the size of the argument list does not match the number of declared arguments for the constructor, or if the method is not a constructor.
      `ClassNotLoadedException` - if any argument type has not yet been loaded through the appropriate class loader.
      `IncompatibleThreadStateException` - if the specified thread has not been suspended by an event.
      `InvocationException` - if the method invocation resulted in an exception in the target VM.
      `InvalidTypeException` - If the arguments do not meet this requirement -- Object arguments must be assignment compatible with the argument type. This implies that the argument type must be loaded through the enclosing class' class loader. Primitive arguments must be either assignment compatible with the argument type or must be convertible to the argument type without loss of information. See JLS section 5.2 for more information on assignment compatibility.
      `VMCannotBeModifiedException` - if the VirtualMachine is read-only - see `VirtualMachine.canBeModified()`.

  - ### concreteMethodByName

    Method concreteMethodByName(String name, String signature)
    Returns a single non-abstract `Method` visible from this class that has the given name and signature. See `ReferenceType.methodsByName(java.lang.String, java.lang.String)` for information on signature format.

    The returned method (if non-null) is a component of `ClassType`.

    Parameters:
      `name` - the name of the method to find.
      `signature` - the signature of the method to find
    Returns:
      the `Method` that matches the given name and signature or `null` if there is no match.
    Throws:
      `ClassNotPreparedException` - if methods are not yet available because the class has not yet been prepared.
    See Also:
      - `ReferenceType.visibleMethods()`
      - `ReferenceType.methodsByName(java.lang.String name)`
      - `ReferenceType.methodsByName(java.lang.String name, java.lang.String signature)`