Type conversions
Type conversion is a technique in wich variables of different types can be assigned to each other. There are two types of type conversions implicit and explicit. Implicit conversions are handled automatically by the compiler or runtime engine and explicit conversions are handled by the developer.
Basic scalars
The following table describes how the conversion of basic scalars works:
Source | Destination | Conversion method | Conversion test | Conversion errors | How the conversion is done |
---|---|---|---|---|---|
|
| - | - | - | |
|
| automatic | - | - | |
|
| - | - | - | |
|
| automatic | - | - | 10 => "10" |
|
| automatic | - | - | 1 => true; value != 0 => false |
|
|
| - | - | Returns the integer part. Any fractional part of this decimal will be discarded. No rounding. |
|
| - | - | - | |
|
| - | - | - | |
|
|
| - | - | |
|
| automatic | - | - | 1 => true; value != 0 => false |
|
| - | - | - | |
|
| - | - | - | |
|
| - | - | - | |
|
|
| - | - | The date in ISO8601 format. |
|
| - | - | - | |
|
|
|
| yes | |
|
|
|
| yes | |
|
|
|
| yes | true => if the string is a valid ISO8601 date, false otherwise |
|
| - | - | - | |
|
|
| - | - | |
|
| automatic | - | - | true => 1; false => 0 |
|
| automatic | - | - | true => 1; false => 0 |
|
| - | - | - | |
|
| automatic | - | - | true => "true"; false => "false" |
|
| - | - | - |
Complex scalars
Complex scalars can be implicitly converted by the compiler or runtime engine only if all the properties of the destination type are found in the source type with the same name and type. The following table exemplifies all the valid implicit conversions:
Source | Destination | Conversion method | How the conversion is done |
---|---|---|---|
|
| automatic | Properties |
|
| automatic | Properties |
|
| - | Conversion must be handled by the developer because |
|
| - | Conversion must be handled by the developer because |
|
| Conversion must be handled by the developer because |