Class Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Instances of the class Class
represent classes and interfaces
in a running Java application.
[Android.Runtime.Register("java/lang/Class", DoNotGenerateAcw=true)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public sealed class Class : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Lang.Invoke.ITypeDescriptor.IOfField, Java.Lang.Reflect.IGenericDeclaration, Java.Lang.Reflect.IType
[<Android.Runtime.Register("java/lang/Class", DoNotGenerateAcw=true)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
type Class = class
inherit Object
interface ISerializable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
interface ITypeDescriptor.IOfField
interface ITypeDescriptor
interface IGenericDeclaration
interface IAnnotatedElement
interface IType
- Inheritance
- Attributes
- Implements
Remarks
Instances of the class Class
represent classes and interfaces in a running Java application. An enum type is a kind of class and an annotation type is a kind of interface. 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. The primitive Java types (boolean
, byte
, char
, short
, int
, long
, float
, and double
), and the keyword void
are also represented as Class
objects.
Class
has no public constructor. Instead a Class
object is constructed automatically by the Java Virtual Machine when a class loader invokes one of the ClassLoader#defineClass(String,byte[], int,int) defineClass
methods and passes the bytes of a class
file.
The methods of class Class
expose many characteristics of a class or interface. Most characteristics are derived from the class
file that the class loader passed to the Java Virtual Machine. A few characteristics are determined by the class loading environment at run time.
Some methods of class Class
expose whether the declaration of a class or interface in Java source code was <em>enclosed</em> within another declaration. Other methods describe how a class or interface is situated in a <em>nest</em>. A "nest">nest is a set of classes and interfaces, in the same run-time package, that allow mutual access to their private
members. The classes and interfaces are known as <em>nestmates</em>. One nestmate acts as the <em>nest host</em>, and enumerates the other nestmates which belong to the nest; each of them in turn records it as the nest host. The classes and interfaces which belong to a nest, including its host, are determined when class
files are generated, for example, a Java compiler will typically record a top-level class as the host of a nest where the other members are the classes and interfaces whose declarations are enclosed within the top-level class declaration.
The following example uses a Class
object to print the class name of an object:
<blockquote>
void printClassName(Object obj) {
System.out.println("The class of " + obj +
" is " + obj.getClass().getName());
}
</blockquote>
It is also possible to get the Class
object for a named type (or for void) using a class literal. See Section 15.8.2 of <cite>The Java™ Language Specification</cite>. For example:
<blockquote> System.out.println("The name of class Foo is: "+Foo.class.getName());
</blockquote>
Some methods of class Class
expose whether the declaration of a class or interface in Java source code was <em>enclosed</em> within another declaration. Other methods describe how a class or interface is situated in a <em>nest</em>. A "nest">nest is a set of classes and interfaces, in the same run-time package, that allow mutual access to their private
members. The classes and interfaces are known as <em>nestmates</em>. One nestmate acts as the <em>nest host</em>, and enumerates the other nestmates which belong to the nest; each of them in turn records it as the nest host. The classes and interfaces which belong to a nest, including its host, are determined when class
files are generated, for example, a Java compiler will typically record a top-level class as the host of a nest where the other members are the classes and interfaces whose declarations are enclosed within the top-level class declaration.
Added in 1.0.
Java documentation for java.lang.Class
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Fields
CharSequence | |
Object | |
String |
Properties
CanonicalName |
Returns the canonical name of the underlying class as defined by the Java Language Specification. |
Class |
Returns the runtime class of this |
ClassLoader |
Returns the class loader for the class. |
ComponentType |
Returns the |
DeclaringClass |
If the class or interface represented by this |
EnclosingClass |
Returns the immediately enclosing class of the underlying class. |
EnclosingConstructor |
If this |
EnclosingMethod |
If this |
GenericSuperclass |
Returns the |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
IsAnnotation |
Returns true if this |
IsAnonymousClass |
Returns |
IsArray |
Determines if this |
IsEnum |
Returns true if and only if this class was declared as an enum in the source code. |
IsInterface |
Determines if the specified |
IsLocalClass |
Returns |
IsMemberClass |
Returns |
IsPrimitive |
Determines if the specified |
IsRecord |
Returns |
IsSealed |
Returns |
IsSynthetic |
Returns |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
Modifiers |
Returns the Java language modifiers for this class or interface, encoded in an integer. |
Name |
Returns the name of the entity (class, interface, array class,
primitive type, or void) represented by this |
NestHost |
Returns the nest host of the nest to which the class
or interface represented by this |
Package |
Gets the package of this class. |
PackageName |
Returns the fully qualified package name. |
PeerReference | (Inherited from Object) |
ProtectionDomain |
Returns the |
SimpleName |
Returns the simple name of the underlying class as given in the source code. |
Superclass |
Returns the |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Object) |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Object) |
TypeName |
Return an informative string for the name of this type. |
Methods
ArrayType() |
Returns a |
AsSubclass(Class) |
Casts this |
Cast(Object) |
Casts an object to the class or interface represented
by this |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
DescriptorString() |
Returns the descriptor string of the entity (class, interface, array class,
primitive type, or |
DesiredAssertionStatus() |
Returns the assertion status that would be assigned to this class if it were to be initialized at the time this method is invoked. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
ForName(String, Boolean, ClassLoader) |
Returns the |
ForName(String) |
Returns the |
FromType(Type) | |
GetAnnotation(Class) |
Added in 1. |
GetAnnotations() |
Added in 1. |
GetAnnotationsByType(Class) |
Added in 1. |
GetClasses() |
Returns an array containing |
GetConstructor(Class[]) |
Returns a |
GetConstructors() |
Returns an array containing |
GetDeclaredAnnotation(Class) |
Added in 1. |
GetDeclaredAnnotations() |
Added in 1. |
GetDeclaredAnnotationsByType(Class) |
Added in 1. |
GetDeclaredClasses() |
Returns an array of |
GetDeclaredConstructor(Class[]) |
Returns a |
GetDeclaredConstructors() |
Returns an array of |
GetDeclaredField(String) |
Returns a |
GetDeclaredFields() |
Returns an array of |
GetDeclaredMethod(String, Class[]) |
Returns a |
GetDeclaredMethods() |
Returns an array containing |
GetEnumConstants() |
Returns the elements of this enum class or null if this Class object does not represent an enum type. |
GetField(String) |
Returns a |
GetFields() |
Returns an array containing |
GetGenericInterfaces() |
Returns the |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetInterfaces() |
Returns the interfaces directly implemented by the class or interface represented by this object. |
GetMethod(String, Class[]) |
Returns a |
GetMethods() |
Returns an array containing |
GetNestMembers() |
Returns an array containing |
GetPermittedSubclasses() |
Returns an array containing |
GetRecordComponents() |
Returns an array of |
GetResource(String) |
Finds a resource with a given name. |
GetResourceAsStream(String) |
Finds a resource with a given name. |
GetSigners() |
Gets the signers of this class. |
GetTypeParameters() |
Returns an array of |
InvokeComponentType() |
Returns the component type of this |
IsAnnotationPresent(Class) |
To be added |
IsAssignableFrom(Class) |
Determines if the class or interface represented by this
|
IsInstance(Object) |
Determines if the specified |
IsNestmateOf(Class) |
Determines if the given |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
NewInstance() |
Creates a new instance of the class represented by this |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
ToArray<T>() | (Inherited from Object) |
ToGenericString() |
Returns a string describing this |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
ITypeDescriptor+IOfField.ComponentType() |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |