O'Reilly logo

The Java® Language Specification, Java SE 7 Edition, Fourth Edition by Alex Buckley, Gilad Bracha, Guy Steele, Bill Joy, James Gosling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required