It is sometimes useful to treat an
expression as if it belonged to different type. A typecast allows you to do
this by, in effect, temporarily changing an expression’s type. For example,
Integer('A') casts the character A as an integer.
The syntax for a typecast is
typeIdentifier(expression)
If the expression is a variable,
the result is called a variable typecast; otherwise, the result is a value
typecast. While their syntax is the same, different rules apply to the two
kinds of typecast.
Data types and variables: Overview
把一个表达式视为另一个不同的类型有时候是有用的。类型转换允许临时有效改变一个表达式的类型。例如,Integer(‘A’)将字符A转换为一个整数。
类型转换的语法是:
typeIdentifier(expression)
如果表达式是一个变量,那么结果叫做变量类型转换,否则叫做值类型转换。虽然二者语法相同,但它们适用两种不同的类型转换规则。