Android Guides | Samples

Java.Lang.Class Class

The in-memory representation of a Java class.

See Also: Class

Syntax

[Android.Runtime.Register("java/lang/Class", DoNotGenerateAcw=true)]
public sealed class Class : Object, ISerializable, IGenericDeclaration, IType, IDisposable

Remarks

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 descriptor, which is the letter "L", followed by the class name and a semicolon (";"). The descriptor 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 descriptors 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

  • [I representing the int[] type
  • [Ljava/lang/String; representing the String[] type
  • [[[C representing the char[][][] type (three dimensions!)

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 descriptor of the class representing the leaf component type, which can be either an object type or a primitive type. The descriptor of a Class representing an array type is the same as its name. Examples of array class descriptors are:

[Android Documentation]

Requirements

Namespace: Java.Lang
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.Lang.Class are listed below.

See Also: Object

Public Fields

static readonly
CharSequenceIntPtr.
static readonly
ObjectIntPtr.
static readonly
StringIntPtr.

Public Properties

[read-only]
CanonicalNameString. Returns the canonical name of this class.
[read-only]
ClassLoaderClassLoader. Returns the class loader which was used to load the class represented by this Class.
[read-only]
ComponentTypeClass. Returns a Class object which represents the component type if this class represents an array type.
[read-only]
DeclaringClassClass. Returns the class that this class is a member of, or null if this class is a top-level class, a primitive, an array, or defined within a method or constructor.
[read-only]
EnclosingClassClass. Returns the class enclosing this class.
[read-only]
EnclosingConstructorConstructor. Returns the enclosing Constructor of this Class, if it is an anonymous or local/automatic class; otherwise null.
[read-only]
EnclosingMethodMethod. Returns the enclosing Method of this Class, if it is an anonymous or local/automatic class; otherwise null.
[read-only]
GenericSuperclassIType. Returns the Type that represents the superclass of this class.
[read-only]
IsAnnotationBoolean. Tests whether this Class represents an annotation class.
[read-only]
IsAnonymousClassBoolean. Tests whether the class represented by this Class is anonymous.
[read-only]
IsArrayBoolean. Tests whether the class represented by this Class is an array class.
[read-only]
IsEnumBoolean. Tests whether the class represented by this Class is an enum.
[read-only]
IsInterfaceBoolean. Tests whether this Class represents an interface.
[read-only]
IsLocalClassBoolean. Tests whether the class represented by this Class is defined locally.
[read-only]
IsMemberClassBoolean. Tests whether the class represented by this Class is a member class.
[read-only]
IsPrimitiveBoolean. Tests whether this Class represents a primitive type.
[read-only]
IsSyntheticBoolean. Tests whether this Class represents a synthetic type.
[read-only]
ModifiersInt32. Returns an integer that represents the modifiers of the class represented by this Class.
[read-only]
NameString. Returns the name of the class represented by this Class.
[read-only]
PackagePackage. Returns the Package of which the class represented by this Class is a member.
[read-only]
ProtectionDomainProtectionDomain. Returns null.
[read-only]
SimpleNameString. Returns the simple name of the class represented by this Class as defined in the source code.
[read-only]
SuperclassClass. Returns the Class object which represents the superclass of the class represented by this Class.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

AsSubclass(Class) : Class
Cast(Object) : Object
Casts the given object to the type represented by this Class.
DesiredAssertionStatus() : Boolean
Returns the assertion status for the class represented by this Class.
static
ForName(String) : Class
Returns a Class object which represents the class with the given name.
static
ForName(String, Boolean, ClassLoader) : Class
Returns a Class object which represents the class with the given name.
static
FromType(Type) : Class
GetAnnotation(Class) : Object
GetAnnotations() : IAnnotation[]
Returns an array containing all the annotations of this class.
GetClasses() : Class[]
Returns an array containing Class objects for all public classes, interfaces, enums and annotations that are members of this class and its superclasses.
GetConstructor(params Class[]) : Constructor
GetConstructors() : Constructor[]
Returns an array containing Constructor objects for all public constructors for this Class.
GetDeclaredAnnotations() : IAnnotation[]
Returns the annotations that are directly defined on the class represented by this Class.
GetDeclaredClasses() : Class[]
Returns an array containing Class objects for all classes, interfaces, enums and annotations that are members of this class.
GetDeclaredConstructor(params Class[]) : Constructor
GetDeclaredConstructors() : Constructor[]
Returns an array containing Constructor objects for all constructors declared in the class represented by this Class.
GetDeclaredField(String) : Field
Returns a Field object for the field with the given name which is declared in the class represented by this Class.
GetDeclaredFields() : Field[]
Returns an array containing Field objects for all fields declared in the class represented by this Class.
GetDeclaredMethod(String, params Class[]) : Method
GetDeclaredMethods() : Method[]
Returns an array containing Method objects for all methods declared in the class represented by this Class.
GetEnumConstants() : Object[]
Returns the enum constants associated with this Class.
GetField(String) : Field
Returns a Field object which represents the public field with the given name.
GetFields() : Field[]
Returns an array containing Field objects for all public fields for the class C represented by this Class.
GetGenericInterfaces() : IType[]
Returns the ITypes of the interfaces that this Class directly implements.
GetInterfaces() : Class[]
Returns an array of Class objects that match the interfaces in the implements declaration of the class represented by this Class.
GetMethod(String, params Class[]) : Method
GetMethods() : Method[]
Returns an array containing Method objects for all public methods for the class C represented by this Class.
GetResource(String) : URL
Returns the URL of the given resource, or null if the resource is not found.
GetResourceAsStream(String) : Stream
Returns a read-only stream for the contents of the given resource, or null if the resource is not found.
GetSigners() : Object[]
Returns null.
GetTypeParameters() : ITypeVariable[]
Returns an array containing TypeVariable objects for type variables declared by the generic class represented by this Class.
IsAnnotationPresent(Class) : Boolean
IsAssignableFrom(Class) : Boolean
IsInstance(Object) : Boolean
Tests whether the given object can be cast to the class represented by this Class.
NewInstance() : Object
Returns a new instance of the class represented by this Class, created by invoking the default (that is, zero-argument) constructor.