请参阅下面的代码。它编译:
int[] arr = new int[2];
System.out.println(arr.toString());
现在,在任何原始类型上,您都不能调用toString()
在 Object 类中定义的 method()(或者,任何相关的方法)......所以,数组本质上是一个Object
.
好的,给你:
从JLS 第 4.3 节:
有四种引用类型:类类型(第 8 节)、接口类型(第 9 节)、类型变量(第 4.4 节)和数组类型(第 10 节)。
并且,第 10 节:
In the Java programming language, arrays are objects (§4.3.1), are
dynamically created, and may be assigned to variables of type Object
(§4.3.2). All methods of class Object may be invoked on an array.
So, from the first quote, Array
is not actually a class... It is another type. But, essentially arrays are objects, though not of some Class
, but they are of Array
type. So they are not instances of some class, and may be objects of array
are defined to be created that way...