1.词汇
- Array covariance 数组协变
- type safety 类型安全
- at compile time 编译时
- at execution time 执行时
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.
如果运行上面的清单,您会看到抛出了一个ArrayTypeMismatchException类型的异常,这是因为从string[]到object[]的转换返回了原始引用,字符串和对象都引用同一个数组。
-
The array itself knows it’s a string array and will reject attempts to store references to nonstrings.
数组本身知道它是一个字符串数组,并将拒绝存储对非字符串的引用的尝试。
-
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.
数组协变有时会派上用场,但它的代价是在执行时而不是在编译时实现类型安全性。