15.16. Cast Expressions

A cast expression converts, at run time, a value of one numeric type to a similar value of another numeric type; or confirms, at compile time, that the type of an expression is boolean; or checks, at run time, that a reference value refers to an object whose class is compatible with a specified reference type.

The parentheses and the type they contain are sometimes called the cast operator.

CastExpression:    ( PrimitiveType ) UnaryExpression    ( ReferenceType ) UnaryExpressionNotPlusMinus

See §15.15 for a discussion of the distinction between UnaryExpression and UnaryExpressionNotPlusMinus.

The type of a cast expression is the result of applying capture conversion (§5.1.10) to the type whose name appears within the parentheses. ...

Get The Java® Language Specification, Java SE 7 Edition, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.