3.9. Casts and Conversions

In a strongly typed language it is sometimes necessary to make conversions between one data type and another. Perhaps you need to perform an operation that accepts a value of a particular type, so you need to convert the type. You can legally convert one numeric type to another, as shown in Table 3.9.

The compiler will automatically assign a smaller type to a larger type. Because no data would be lost, this operation is unproblematic. However, data of a larger type will not automatically be converted to a smaller type—even if the smaller type is sufficiently large to hold the data—because the compiler cannot know if the data's integrity will be maintained. To perform this kind of assignment, a typecast is required. ...

Get Java™ for ColdFusion® Developers 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.