liveBook · Manning

Unchecked cast

An unchecked cast is a type conversion whose compatibility with the target type cannot be fully verified at compile time or runtime, often because type information is unavailable or erased.

How 2 Manning books explain it

Kotlin in Action, 2E

An unchecked cast is a cast whose generic type compatibility cannot be verified by the compiler or runtime because the relevant type information is unavailable.

How it is used
Handles generic values whose base type is known while erased type arguments cannot be verified at runtime.
How deep it goes
Explains erased generic checks through collection and validator failures, then develops an encapsulated generic registry pattern.
Examples
Demonstrates summing collections and retrieving String or Int field validators from a heterogeneous map.
What you can do after
Evaluate/understand when a generic cast can succeed yet later throw ClassCastException, and localize necessary unsafe casts.

Read how Kotlin in Action, 2E explains unchecked cast →

100 Java Mistakes and How to Avoid Them

An unchecked cast is a cast whose compatibility cannot be fully verified by the compiler or at runtime because of erased generic type information.

How it is used
Warns against generic casts that silently corrupt collections and fail later during typed access.
How deep it goes
Explains type erasure, compiler-inserted casts, a corrupting write, and wildcard or wrapper alternatives.
Examples
Uses a `List<String>` cast through `List<?>` to `List<Object>`, then inserts an `Integer` before a typed read.
What you can do after
Evaluate/understand where unchecked generic casts defer ClassCastException and replace many with wildcards or wrappers.

Read how 100 Java Mistakes and How to Avoid Them explains unchecked cast →

What to know first

Related concepts

Questions about unchecked cast

What is unchecked cast?

An unchecked cast is a type conversion whose compatibility with the target type cannot be fully verified at compile time or runtime, often because type information is unavailable or erased.

Which Manning books explain unchecked cast?

Kotlin in Action, 2E and 100 Java Mistakes and How to Avoid Them.

What should I know before learning unchecked cast?

Manning books that teach unchecked cast usually introduce generics first.

What is the difference between unchecked cast and explicit conversion?

An unchecked cast is a type conversion whose compatibility with the target type cannot be fully verified at compile time or runtime, often because type information is unavailable or erased. An explicit conversion is a programmer-directed transformation of a value from one data type or representation to another.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.