Straight from the API Specifications for the ClassCastException
:
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
So, for example, when one tries to cast an Integer
to a String
, String
is not an subclass of Integer
, so a ClassCastException
will be thrown.
Object i = Integer.valueOf(42); String s = (String)i; // ClassCastException thrown here.
Related Posts:
- Convert String to double in Java
- Casting variables in Java
- Converting double to integer in Java
- How do I convert a string to a number in PHP?
- dynamic_cast and static_cast in C++
- Convert an integer to an array of characters : java
- If Java is Strongly typed then why does this code compile?
- Downcasting in Java
- Convert Int to String in Swift
- C convert floating point to int
- How to cast ArrayList<> from List<>
- Convert boolean to int in Java
- Typescript: Index signature is missing in type
- How to cast ArrayList<> from List<>
- Why cannot cast Integer to String in java?
- Java rules for casting
- max value of integer
- “Error occurred during initialization of VM; Could not reserve enough space for object heap” using -Xmx3G
- “int cannot be dereferenced” in Java
- What is a Key-Value Pair?
- Create ArrayList from array
- How to get current timestamp in string format in Java? “yyyy.MM.dd.HH.mm.ss”
- What is null in Java?
- What is an illegal reflective access?
- Convert Set to List without creating new List
- Global variables in Java
- Does the Project Lombok @Data annotation create a constructor of any kind?
- Javac is not found
- Meaning of *= in Java
- Ignoring upper case and lower case in Java
- Please initialize the log4j system properly. While running web service
- ‘mvn’ is not recognized as an internal or external command, operable program or batch file
- What does .class mean in Java?
- What does the following Oracle error mean: invalid column index
- how to fix java.lang.arrayindexoutofboundsexception: 0?
- Convert the string into stringBuilder in java
- How do I check if a string is a number (float)?
- “NoClassDefFoundError: Could not initialize class” error
- Print ArrayList
- How to create PPTP connection with Java?
- Error: A JNI error has occurred, please check your installation and try again – during running Java program from Ubuntu terminal
- Unrecognized SSL message, plaintext connection? Exception
- What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
- How to create an empty array?
- How to decompile a whole Jar file?
- possible lossy conversion from long to int?
- Guess a number program with Java
- How do I set the proxy to be used by the JVM
- Where to get the tools.jar to use with the Java 8 jdk early release
- int cannot be converted to string?
- Returning null in a method whose signature says return int?
- keytool error Keystore was tampered with, or password was incorrect
- Difference between a HashMap and a dictionary ADT
- Converting A String To Hexadecimal In Java
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- Enqueue, Dequeue and ViewQueue in Java
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- Running Command Line in Java
- Working Soap client example
- Simple Dropdown menu in Java
- Invalid escape sequence (valid ones are \b \t \n \f \r \” \’ \\ )
- JDK was not found on the computer for NetBeans 6.5
- In Java, how to assign the variable number=Integer.parseInt(args[0]) a value if no argument is passed?
- How to use the command update-alternatives –config java
- How are “mvn clean package” and “mvn clean install” different?
- What is a hash function in java?
- Why are two empty ArrayLists with different generic types equal?
- java.lang.VerifyError: Inconsistent stackmap frames at branch target 421
- tic tac toe java user vs computer
- Java Wait for thread to finish
- How to convert an Instant to a date format?
- equivalent to push() or pop() for arrays?
- JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”
- How do I fix a NoSuchMethodError?
- What is the Java equivalent for LINQ?
- what is update-alternatives command in linux and what is the use of it?
- java: use StringBuilder to insert at the beginning
- Multiple delimiters in Scanner class of Java
- Eclipse Problems View not showing Errors anymore
- C# equivalent to Java’s charAt()?
- unexpected type error
- What does it mean: The serializable class does not declare a static final serialVersionUID field? [duplicate]
- “Cannot be resolved to a type” when attempting to use Scanner
- Converting a 2-3-4 tree into a red black tree
- Generic stack implementation
- Java generating non-repeating random numbers
- java eclipse red exclamation mark
- Java FileOutputStream Create File if not exists
- Configure active profile in SpringBoot via Maven
- Is there any way to program Java on Visual Studio 2015
- Byte and char conversion in Java
- Java “lambda expressions not supported at this language level”
- How to specify filepath in java?
- Issue installing Netbeans in Windows 10: Java SE Development Kit (JDK) was not found on this computer
- dequeue and enqueue methods in queue implementation
- How to specify the default error page in web.xml?
- Exception is never thrown in body of corresponding try statement
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- Using while loop as input validation [duplicate]
- java -version and javac -version showing different versions