只是好奇:
有人知道为什么 System.arraycopy
方法使用 Object
作为 src
和 dest
的类型吗?完全有可能改用 Object[]
吗?
为什么定义:
arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
代替
arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length)
?
最佳答案
boolean[]
和 double[]
等基本数组类型不扩展 Object[]
但它们扩展 Object
这个方法允许你复制任何类型的数组,所以类型是Object。
int[] a =
int[] b =
System.arraycopy(a, 0, b, 0, a.length);
关于java - 为什么 "System.arraycopy"使用 "Object"而不是 "Object[]"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6289923/