[英]Why is java “highest” superclass called “Object”?
I have a strange (and maybe silly) question: I was wondering.... why is java "Object" class called "Object", not "Class"? 我有一个奇怪的(也许是愚蠢的)问题:我在想......为什么java“Object”类叫做“Object”而不是“Class”?
For example, for ArrayList whe have the following hierarchy 例如,对于ArrayList,具有以下层次结构
Object ->
Collection ->
List ->
ArrayList
Ok: ArrayList is a List... List is a Collection... but a Collection (the class of all collections) is not an Object... it is a class! 好的:ArrayList是一个List ... List是一个Collection ...但是Collection(所有集合的类)不是一个Object ......它是一个类!
Think about what the object itself is. 想想对象本身是什么。 An
ArrayList
is a list, yes? ArrayList
是一个列表,是吗? It's also an object. 它也是一个对象。 It's not a class of object.
它不是一类对象。 The class name describes what instances of that class represent.
类名描述该类的哪些实例代表。
A collection isn't a class of collections - it's a collection (and it's an object). 集合不是一类集合 - 它是一个集合 (它是一个对象)。
Well, you use Object
to declare an instance of a (not better specified) Object, same as you use Collection
to declare an instance of a Collection. 那么,你使用
Object
来声明(不是更好指定)对象的实例 ,一样的,你用Collection
来声明集合的实例 。
You can declare an object of type Class too, with java.lang.Class<T>
, where an instance of it represents the Class of the Object 您也可以使用
java.lang.Class<T>
声明类型为Class的对象,其中一个实例表示Object的Class
Collection
is an interface (effectively a special type of class). Collection
是一个接口(实际上是一种特殊类型的接口)。
A Collection
is an object. 一个
Collection
是一个对象。
Your assumption is incorrect. 你的假设不正确。 The correct hiearchy for ArrayList is:
ArrayList的正确层次结构是:
ArrayList --> AbstractList --> AbstractCollection --> Object ArrayList - > AbstractList - > AbstractCollection - > Object
So even ArrayList has Object as the first thing in its hierarchy. 因此,即使ArrayList也将Object作为其层次结构中的第一件事。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.