1.詞匯
- Array covariance 數(shù)組協(xié)變
- type safety 類型安全
- at compile time 編譯時
- at execution time 執(zhí)行時
2.例句
- code listing 代碼清單
string[] strings = new string[5];
object[] objects = strings;
objects[0] = new Button();
-
If you run listing above, you’ll see that an ArrayTypeMismatchException is thrown, This is because the conversion from string[] to object[] returns the original reference—both strings and objects refer to the same array.
如果運(yùn)行上面的清單,您會看到拋出了一個ArrayTypeMismatchException類型的異常,這是因?yàn)閺膕tring[]到object[]的轉(zhuǎn)換返回了原始引用,字符串和對象都引用同一個數(shù)組。
-
The array itself knows it’s a string array and will reject attempts to store references to nonstrings.
數(shù)組本身知道它是一個字符串?dāng)?shù)組,并將拒絕存儲對非字符串的引用的嘗試。
-
Array covariance is occasionally useful, but it comes at the cost of implementing some of the type safety at execution time instead of compile time.
數(shù)組協(xié)變有時會派上用場,但它的代價是在執(zhí)行時而不是在編譯時實(shí)現(xiàn)類型安全性。