type cast

An instruction to treat a value as a more specific type, written (String) value, which fails at runtime if the value is not that type.

In more detail

A failed cast throws ClassCastException. Generics and pattern matching exist largely to remove casts: the compiler proves the type instead of the programmer promising it.

Example

String text = (String) value;

Related terms

Taught in

References

Certification courses