Stay organized with collections
Save and categorize content based on your preferences.
ClassCastException
open class ClassCastException : RuntimeException
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException
:
Object x = new Integer(0);
System.out.println((String)x);
Summary
Public constructors |
Constructs a ClassCastException with no detail message.
|
Constructs a ClassCastException with the specified detail message.
|
Public constructors
ClassCastException
ClassCastException()
Constructs a ClassCastException
with no detail message.
ClassCastException
ClassCastException(s: String!)
Constructs a ClassCastException
with the specified detail message.
Parameters |
s |
String!: the detail message. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# ClassCastException\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nClassCastException\n==================\n\n```\nopen class ClassCastException : RuntimeException\n```\n\n|---|---|---|---|-----------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||||\n| ↳ | [kotlin.Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html) ||||\n| | ↳ | [java.lang.Exception](/reference/kotlin/java/lang/Exception) |||\n| | | ↳ | [java.lang.RuntimeException](/reference/kotlin/java/lang/RuntimeException) ||\n| | | | ↳ | [java.lang.ClassCastException](#) |\n\nThrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a `ClassCastException`: \n\n```kotlin\nObject x = new Integer(0);\n System.out.println((String)x);\n \n```\n\n\u003cbr /\u003e\n\nSummary\n-------\n\n| Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [ClassCastException](#ClassCastException())`()` Constructs a `ClassCastException` with no detail message. |\n| [ClassCastException](#ClassCastException(kotlin.String))`(`s:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Constructs a `ClassCastException` with the specified detail message. |\n\nPublic constructors\n-------------------\n\n### ClassCastException\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nClassCastException()\n```\n\nConstructs a `ClassCastException` with no detail message. \n\n### ClassCastException\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nClassCastException(s: String!)\n```\n\nConstructs a `ClassCastException` with the specified detail message.\n\n| Parameters ||\n|-----|--------------------------------------------------------------------------------------------------------|\n| `s` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: the detail message. |"]]