类型转换/类型强制转换:在编程中把一个值从一种数据类型转换为另一种数据类型的操作。常见于把整数转为浮点数、把父类引用转为子类、或在不同数值类型之间转换。某些语言区分显式转换(cast)与隐式转换(coercion)。
I had to do type casting to turn the integer into a float.
我不得不做类型转换,把整数变成浮点数。
Incorrect type casting can cause data loss or runtime errors, especially when converting large numbers or downcasting objects.
不正确的类型强制转换可能导致数据丢失或运行时错误,尤其是在转换大数值或对对象进行向下转型时。
/taɪp ˈkæstɪŋ/
type 来自希腊语 typos(“印记、模型、类型”),后来在英语中发展出“类别/类型”的含义;cast 原意与“投掷、浇铸成型”相关。在编程语境里,cast 比喻“把值‘铸成’另一种类型的形状”,因此 type casting 就是“把数据按另一种类型来解释或转换”。