O'Reilly logo

Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams by Jamie Jaworski

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

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

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