Tuesday, November 25, 2008

Type conversion and casting

It is fairly common to assign a value of one type to a variable of another type. If two types are compatible, then Java will perform the conversion automatically. It is always possible to assign an int value to a long variable. However not all types are compatible and thus, not all type conversions are implicitly allowed. For instance there is no conversion defined from double to byte. Fortunately it is possible to obtain a conversion between incompatible types.

0 comments: