Interface ReferenceType
- All Superinterfaces:
- Accessible,- Comparable<ReferenceType>,- Mirror,- Type
- All Known Subinterfaces:
- ArrayType,- ClassType,- InterfaceType
ClassType for classes,
 InterfaceType for interfaces, and
 ArrayType for arrays.
 Note that primitive classes (for example, the
 reflected type of
 Integer.TYPE)
 are represented as ClassType.
 The VM creates Class objects for all three, so from the VM perspective,
 each ReferenceType maps to a distinct Class object.
 
 ReferenceTypes can
 be obtained by querying a particular ObjectReference for its
 type or by getting a list of all reference types from the
 VirtualMachine.
 
ReferenceType provides access to static type information such as methods and fields and provides access to dynamic type information such as the corresponding Class object and the classloader.
 Any method on ReferenceType which directly or
 indirectly takes ReferenceType as an parameter may throw
 VMDisconnectedException if the target VM is
 disconnected and the VMDisconnectEvent has been or is
 available to be read from the EventQueue.
 
 Any method on ReferenceType which directly or
 indirectly takes ReferenceType as an parameter may throw
 VMOutOfMemoryException if the target VM has run out of memory.
 
 Any method on ReferenceType or which directly or indirectly takes
 ReferenceType as parameter may throw
 ObjectCollectedException if the mirrored type has been unloaded.
- Since:
- 1.3
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionReturns a list containing eachFielddeclared in this type, and its superclasses, implemented interfaces, and/or superinterfaces.Returns a list containing aLocationobject for each executable source line in this reference type.allLineLocations(String stratum, String sourceName) Returns a list containing aLocationobject for each executable source line in this reference type.Returns a list containing eachMethoddeclared in this type, and its superclasses, implemented interfaces, and/or superinterfaces.Return the available strata for this reference type.Gets the classloader object which loaded the class corresponding to this type.Returns the class object that corresponds to this type in the target VM.byte[]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.intReturns the number of entries in the constant pool plus one.Returns the default stratum for this reference type.booleanCompares the specified Object with this ReferenceType for equality.booleanDetermines if initialization failed for this class.fieldByName(String fieldName) Finds the visibleFieldwith the given non-ambiguous name.fields()Returns a list containing eachFielddeclared in this type.Gets the generic signature for this type if there is one.inthashCode()Returns the hash code value for this ObjectReference.instances(long maxInstances) Returns instances of this ReferenceType.booleanDetermines if this type was declared abstract.booleanisFinal()Determines if this type was declared final.booleanDetermines if this type has been initialized.booleanDetermines if this type has been prepared.booleanisStatic()Determines if this type was declared static.booleanDetermines if this type has been verified.locationsOfLine(int lineNumber) Returns a List containing allLocationobjects that map to the given line number.locationsOfLine(String stratum, String sourceName, int lineNumber) Returns a List containing allLocationobjects that map to the given line number.intReturns the class major version number, as defined in the class file format of the Java Virtual Machine Specification.methods()Returns a list containing eachMethoddeclared directly in this type.methodsByName(String name) Returns a List containing each visibleMethodthat has the given name.methodsByName(String name, String signature) Returns a List containing each visibleMethodthat has the given name and signature.intReturns the class minor version number, as defined in the class file format of the Java Virtual Machine Specification.default ModuleReferencemodule()Gets the module object which contains the class corresponding to this type.name()Returns the name of thisReferenceTypeobject.Returns a List containingReferenceTypeobjects that are declared within this type and are currently loaded into the Virtual Machine.Get the source debug extension of this type.Gets an identifying name for the source corresponding to the declaration of this type.sourceNames(String stratum) Gets the identifying names for all the source corresponding to the declaration of this type.sourcePaths(String stratum) Gets the paths to the source corresponding to the declaration of this type.Returns a list containing each unhidden and unambiguousFieldin this type.Returns a list containing eachMethoddeclared or inherited by this type.Methods declared in interface com.sun.jdi.AccessibleisPackagePrivate, isPrivate, isProtected, isPublic, modifiersMethods declared in interface java.lang.ComparablecompareToMethods declared in interface com.sun.jdi.MirrortoString, virtualMachine
- 
Method Details- 
nameString name()Returns the name of thisReferenceTypeobject. The returned name is of the same form as the name returned byClass.getName().
- 
genericSignatureString genericSignature()Gets the generic signature for this type if there is one. Generic signatures are described in the The Java Virtual Machine Specification.- Returns:
- a string containing the generic signature, or nullif there is no generic signature.
- Since:
- 1.5
 
- 
classLoaderClassLoaderReference classLoader()Gets the classloader object which loaded the class corresponding to this type.- Returns:
- a ClassLoaderReferencewhich mirrors the classloader, ornullif the class was loaded through the bootstrap class loader.
 
- 
moduleGets the module object which contains the class corresponding to this type. Not all target virtual machines support this operation. UseVirtualMachine.canGetModuleInfo()to determine if the operation is supported.- Implementation Requirements:
- The default implementation throws UnsupportedOperationException.
- Returns:
- a ModuleReferencewhich mirrors the module in the target VM.
- Throws:
- UnsupportedOperationException- if the target virtual machine does not support this operation.
- Since:
- 9
 
- 
sourceNameGets an identifying name for the source corresponding to the declaration of this type. Interpretation of this string is the responsibility of the source repository mechanism.The returned name is dependent on VM's default stratum ( VirtualMachine.getDefaultStratum()). In the reference implementation, when using the base stratum, the returned string is the unqualified name of the source file containing the declaration of this type. In other strata the returned source name is the first source name for that stratum. Since other languages may have more than one source name for a reference type, the use ofLocation.sourceName()orsourceNames(String)is preferred.For arrays ( ArrayType) and primitive classes, AbsentInformationException is always thrown.- Returns:
- the string source file name
- Throws:
- AbsentInformationException- if the source name is not known
 
- 
sourceNamesGets the identifying names for all the source corresponding to the declaration of this type. Interpretation of these names is the responsibility of the source repository mechanism.The returned names are for the specified stratum (see Locationfor a description of strata). In the reference implementation, when using the Java programming language stratum, the returned List contains one element: a String which is the unqualified name of the source file containing the declaration of this type. In other strata the returned source names are all the source names defined for that stratum.- Parameters:
- stratum- The stratum to retrieve information from or- nullfor the declaring type's default stratum.
- Returns:
- a List of String objects each representing a source name
- Throws:
- AbsentInformationException- if the source names are not known.- For arrays ( - ArrayType) and primitive classes, AbsentInformationException is always thrown.
- Since:
- 1.4
 
- 
sourcePathsGets the paths to the source corresponding to the declaration of this type. Interpretation of these paths is the responsibility of the source repository mechanism.The returned paths are for the specified stratum (see Locationfor a description of strata). In the reference implementation, for strata which do not explicitly specify source path (the Java programming language stratum never does), the returned strings are thesourceNames(String)prefixed by the package name of this ReferenceType converted to a platform dependent path. For example, on a Windows platform,java.lang.Threadwould return a List containing one element:"java\lang\Thread.java".- Parameters:
- stratum- The stratum to retrieve information from or- nullfor the declaring type's default stratum.
- Returns:
- a List of String objects each representing a source path
- Throws:
- AbsentInformationException- if the source names are not known.- For arrays ( - ArrayType) and primitive classes, AbsentInformationException is always thrown.
- Since:
- 1.4
 
- 
sourceDebugExtensionGet the source debug extension of this type.Not all target virtual machines support this operation. Use canGetSourceDebugExtension()to determine if the operation is supported.- Returns:
- as a string the source debug extension attribute
- Throws:
- AbsentInformationException- if the extension is not specified
- UnsupportedOperationException- if the target virtual machine does not support this operation - see- canGetSourceDebugExtension(),
 
- 
isStaticboolean isStatic()Determines if this type was declared static. Only nested types, can be declared static, sofalseis returned for any package-level type, array type, or primitive class.- Returns:
- trueif this type is static; false otherwise.
 
- 
isAbstractboolean isAbstract()Determines if this type was declared abstract.For arrays ( ArrayType) and primitive classes, the return value is undefined.- Returns:
- trueif this type is abstract; false otherwise.
 
- 
isFinalboolean isFinal()Determines if this type was declared final.For arrays ( ArrayType) and primitive classes, the return value is always true.- Returns:
- trueif this type is final; false otherwise.
 
- 
isPreparedboolean isPrepared()Determines if this type has been prepared. See the JVM specification for a definition of class preparation.For arrays ( ArrayType) and primitive classes, the return value is undefined.- Returns:
- trueif this type is prepared; false otherwise.
 
- 
isVerifiedboolean isVerified()Determines if this type has been verified. See the JVM specification for a definition of class verification.For arrays ( ArrayType) and primitive classes, the return value is undefined.- Returns:
- trueif this type is verified; false otherwise.
 
- 
isInitializedboolean isInitialized()Determines if this type has been initialized. See the JVM specification for a definition of class verification. ForInterfaceType, this method always returns the same value asisPrepared().For arrays ( ArrayType) and primitive classes, the return value is undefined.- Returns:
- trueif this type is initialized; false otherwise.
 
- 
failedToInitializeboolean failedToInitialize()Determines if initialization failed for this class. See the JVM specification for details on class initialization.For arrays ( ArrayType) and primitive classes, the return value is undefined.- Returns:
- trueif initialization was attempted and failed; false otherwise.
 
- 
fieldsReturns a list containing eachFielddeclared in this type. Inherited fields are not included. Any synthetic fields created by the compiler are included in the list.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a list Fieldobjects; the list has length 0 if no fields exist.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
visibleFieldsReturns a list containing each unhidden and unambiguousFieldin this type. Each field that can be accessed from the class or its instances with its simple name is included. Fields that are ambiguously multiply inherited or fields that are hidden by fields with the same name in a more recently inherited class cannot be accessed by their simple names and are not included in the returned list. All other inherited fields are included. See JLS section 8.3 for details.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a List of Fieldobjects; the list has length 0 if no visible fields exist.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
allFieldsReturns a list containing eachFielddeclared in this type, and its superclasses, implemented interfaces, and/or superinterfaces. All declared and inherited fields are included, regardless of whether they are hidden or multiply inherited.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a List of Fieldobjects; the list has length 0 if no fields exist.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
fieldByNameFinds the visibleFieldwith the given non-ambiguous name. This method follows the inheritance rules specified in the JLS (8.3.3) to determine visibility.For arrays ( ArrayType) and primitive classes, the returned value is always null.- Parameters:
- fieldName- a String containing the name of desired field.
- Returns:
- a Fieldobject which mirrors the found field, or null if there is no field with the given name or if the given name is ambiguous.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
methodsReturns a list containing eachMethoddeclared directly in this type. Inherited methods are not included. Constructors, the initialization method if any, and any synthetic methods created by the compiler are included in the list.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a list Methodobjects; the list has length 0 if no methods exist.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
visibleMethodsReturns a list containing eachMethoddeclared or inherited by this type. Methods from superclasses or superinterfaces that have been hidden or overridden are not included.Note that despite this exclusion, multiple inherited methods with the same signature can be present in the returned list, but at most one can be a member of a ClassType. See JLS section 8.4.8 for details.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a List of Methodobjects; the list has length 0 if no visible methods exist.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
allMethodsReturns a list containing eachMethoddeclared in this type, and its superclasses, implemented interfaces, and/or superinterfaces. All declared and inherited methods are included, regardless of whether they are hidden or overridden.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a List of Methodobjects; the list has length 0 if no methods exist.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
methodsByNameReturns a List containing each visibleMethodthat has the given name. This is most commonly used to find overloaded methods.Overridden and hidden methods are not included. See JLS (8.4.8) for details. For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Parameters:
- name- the name of the method to find.
- Returns:
- a List of Methodobjects that match the given name; the list has length 0 if no matching methods are found.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
methodsByNameReturns a List containing each visibleMethodthat has the given name and signature. The signature string is the JNI signature for the target method:- ()V
- ([Ljava/lang/String;)V
- (IIII)Z
 At most one method in the list is a concrete method and a component of ClassType; any other methods in the list are abstract. UseClassType.concreteMethodByName(java.lang.String, java.lang.String)to retrieve only the matching concrete method.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Parameters:
- name- the name of the method to find.
- signature- the signature of the method to find
- Returns:
- a List of Methodobjects that match the given name and signature; the list has length 0 if no matching methods are found.
- Throws:
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
nestedTypesList<ReferenceType> nestedTypes()Returns a List containingReferenceTypeobjects that are declared within this type and are currently loaded into the Virtual Machine. Both static nested types and non-static nested types (that is, inner types) are included. Local inner types (declared within a code block somewhere in this reference type) are also included in the returned list.For arrays ( ArrayType) and primitive classes, the returned list is always empty.- Returns:
- a List of nested ReferenceTypeobjects; the list has 0 length if there are no nested types.
 
- 
getValueGets theValueof a given staticFieldin this type. The Field must be valid for this type; that is, it must be declared in this type, a superclass, a superinterface, or an implemented interface.- Parameters:
- field- the field containing the requested value
- Returns:
- the Valueof the instance field.
- Throws:
- IllegalArgumentException- if the field is not valid for this object's class.
 
- 
getValuesReturns a map containing theValueof each staticFieldin the given list. The Fields must be valid for this type; that is, they must be declared in this type, a superclass, a superinterface, or an implemented interface.- Parameters:
- fields- a list of- Fieldobjects containing the requested values.
- Returns:
- a Map of the requested Fieldobjects with theirValue.
- Throws:
- IllegalArgumentException- if any field is not valid for this object's class.
- VMMismatchException- if a- Mirrorargument and this mirror do not belong to the same- VirtualMachine.
 
- 
classObjectClassObjectReference classObject()Returns the class object that corresponds to this type in the target VM. The VM creates class objects for every kind of ReferenceType: classes, interfaces, and array types.- Returns:
- the ClassObjectReferencefor this reference type in the target VM.
 
- 
allLineLocationsReturns a list containing aLocationobject for each executable source line in this reference type.This method is equivalent to allLineLocations(vm.getDefaultStratum(),null)- seeallLineLocations(String,String)for more information.- Throws:
- AbsentInformationException- if there is no line number information for this class and there are non-native, non-abstract executable members of this class.
- ClassNotPreparedException- if this class not yet been prepared.
 
- 
allLineLocationsList<Location> allLineLocations(String stratum, String sourceName) throws AbsentInformationException Returns a list containing aLocationobject for each executable source line in this reference type. Each location maps a source line to a range of code indices. The beginning of the range can be determined throughLocation.codeIndex(). The returned list may contain multiple locations for a particular line number, if the compiler and/or VM has mapped that line to two or more disjoint code index ranges. Note that it is possible for the same source line to represent different code index ranges in different methods.For arrays ( ArrayType) and primitive classes, the returned list is always empty. For interfaces (InterfaceType), the returned list will be non-empty only if the interface has executable code in its class initialization.Returned list is for the specified stratum (see Locationfor a description of strata).- Parameters:
- stratum- The stratum to retrieve information from or- nullfor the- defaultStratum().
- sourceName- Return locations only within this source file or- nullto return locations.
- Returns:
- a List of all source line Locationobjects.
- Throws:
- AbsentInformationException- if there is no line number information for this class and there are non-native, non-abstract executable members of this class. Or if sourceName is non-- nulland source name information is not present.
- ClassNotPreparedException- if this class not yet been prepared.
- Since:
- 1.4
 
- 
locationsOfLineReturns a List containing allLocationobjects that map to the given line number.This method is equivalent to locationsOfLine(vm.getDefaultStratum(), null, lineNumber)- seelocationsOfLine(java.lang.String,java.lang.String,int)for more information.- Parameters:
- lineNumber- the line number
- Returns:
- a List of all Locationobjects that map to the given line.
- Throws:
- AbsentInformationException- if there is no line number information for this class.
- ClassNotPreparedException- if this class not yet been prepared.
- See Also:
 
- 
locationsOfLineList<Location> locationsOfLine(String stratum, String sourceName, int lineNumber) throws AbsentInformationException Returns a List containing allLocationobjects that map to the given line number.For arrays ( ArrayType) and primitive classes, the returned list is always empty. For interfaces (InterfaceType), the returned list will be non-empty only if the interface has executable code in its class initialization at the specified line number. An empty list will be returned if there is no executable code at the specified line number.Returned list is for the specified stratum (see Locationfor a description of strata).- Parameters:
- stratum- the stratum to use for comparing line number and source name, or- nullto use the- defaultStratum().
- sourceName- the source name containing the line number, or- nullto match all source names
- lineNumber- the line number
- Returns:
- a List of all Locationobjects that map to the given line.
- Throws:
- AbsentInformationException- if there is no line number information for this class. Or if sourceName is non-- nulland source name information is not present.
- ClassNotPreparedException- if this class not yet been prepared.
- Since:
- 1.4
 
- 
availableStrata
- 
defaultStratumString defaultStratum()Returns the default stratum for this reference type. This value is specified in the class file and cannot be set by the user. If the class file does not specify a default stratum the base stratum ("Java") will be returned.See the Locationfor a description of strata.- Since:
- 1.4
 
- 
instancesReturns instances of this ReferenceType. Only instances that are reachable for the purposes of garbage collection are returned.Not all target virtual machines support this operation. Use VirtualMachine.canGetInstanceInfo()to determine if the operation is supported.- Parameters:
- maxInstances- the maximum number of instances to return. Must be non-negative. If zero, all instances are returned.
- Returns:
- a List of ObjectReferenceobjects. If there are no instances of this ReferenceType, a zero-length list is returned.
- Throws:
- UnsupportedOperationException- if the target virtual machine does not support this operation - see- canGetInstanceInfo()
- IllegalArgumentException- if maxInstances is less than zero.
- Since:
- 1.6
- See Also:
 
- 
equalsCompares the specified Object with this ReferenceType for equality.- Overrides:
- equalsin class- Object
- Parameters:
- obj- the reference object with which to compare.
- Returns:
- true if the Object is a ReferenceType, if the ReferenceTypes belong to the same VM, and if they mirror classes which correspond to the same instance of java.lang.Class in that VM.
- See Also:
 
- 
hashCode
- 
majorVersionint majorVersion()Returns the class major version number, as defined in the class file format of the Java Virtual Machine Specification. For arrays (ArrayType) and primitive classes, the returned major version number value is zero. Not all target virtual machines support this operation. UseVirtualMachine.canGetClassFileVersion()to determine if the operation is supported.- Returns:
- the major version number of the class.
- Throws:
- UnsupportedOperationException- if the target virtual machine does not support this operation - see- canGetClassFileVersion()
- Since:
- 1.6
 
- 
minorVersionint minorVersion()Returns the class minor version number, as defined in the class file format of the Java Virtual Machine Specification. For arrays (ArrayType) and primitive classes, the returned minor version number value is zero. Not all target virtual machines support this operation. UseVirtualMachine.canGetClassFileVersion()to determine if the operation is supported.- Returns:
- the minor version number of the class.
- Throws:
- UnsupportedOperationException- if the target virtual machine does not support this operation - see- canGetClassFileVersion()
- Since:
- 1.6
 
- 
constantPoolCountint constantPoolCount()Returns the number of entries in the constant pool plus one. This corresponds to the constant_pool_count item of the Class File Format in the Java Virtual Machine Specification. For arrays (ArrayType) and primitive classes, the returned constant pool count value is zero. Not all target virtual machines support this operation. UseVirtualMachine.canGetConstantPool()to determine if the operation is supported.- Returns:
- total number of constant pool entries for a class plus one.
- Throws:
- UnsupportedOperationException- if the target virtual machine does not support this operation - see- canGetConstantPool()
- Since:
- 1.6
- See Also:
 
- 
constantPoolbyte[] 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. The format of the constant pool may differ between versions of the Class File Format, so, the minor and major class version numbers should be checked for compatibility. For arrays (ArrayType) and primitive classes, a zero length byte array is returned. Not all target virtual machines support this operation. UseVirtualMachine.canGetConstantPool()to determine if the operation is supported.- Returns:
- the raw bytes of constant pool.
- Throws:
- UnsupportedOperationException- if the target virtual machine does not support this operation - see- canGetConstantPool()
- Since:
- 1.6
- See Also:
 
 
-