The Cast Operator

The cast operator (type) is used to convert numeric values from one numeric type to another or to change an object reference to a compatible type.

WIDENING AND NARROWING CONVERSIONS

A widening conversion is a conversion from a smaller numeric type to a larger numeric type. An example of a widening conversion is when a byte value is promoted to an int value. A narrowing conversion is a conversion from a larger numeric type to a smaller numeric type. A conversion from a long value to a short value would be an example of a narrowing conversion. Narrowing conversions require the use of the cast operator.

Casting can be used to enable numeric conversions that would normally be disallowed by the compiler. For example, the following ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams 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.