Share via


Class.AsSubclass(Class) Method

Definition

Casts this Class object to represent a subclass of the class represented by the specified class object.

[Android.Runtime.Register("asSubclass", "(Ljava/lang/Class;)Ljava/lang/Class;", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "U" })]
public Java.Lang.Class AsSubclass (Java.Lang.Class clazz);
[<Android.Runtime.Register("asSubclass", "(Ljava/lang/Class;)Ljava/lang/Class;", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "U" })>]
member this.AsSubclass : Java.Lang.Class -> Java.Lang.Class

Parameters

clazz
Class

the class of the type to cast this class object to

Returns

this Class object, cast to represent a subclass of the specified class object.

Attributes

Remarks

Casts this Class object to represent a subclass of the class represented by the specified class object. Checks that the cast is valid, and throws a ClassCastException if it is not. If this method succeeds, it always returns a reference to this class object.

This method is useful when a client needs to "narrow" the type of a Class object to pass it to an API that restricts the Class objects that it is willing to accept. A cast would generate a compile-time warning, as the correctness of the cast could not be checked at runtime (because generic types are implemented by erasure).

Added in 1.5.

Java documentation for java.lang.Class.asSubclass(java.lang.Class<U>).

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.

Applies to