Does anybody knows when the "class" - an Class attribute was introduced in "Object" class? Even though "class" attribute is part of the "Object" class, it is not part of javadoc, is there any reason, why?
It's not in the Javadoc because it's not "real". It's not a member variable of Object (or any other class) -- it's an abstraction implemented by the compiler. If you use "X.class" in a program, then somewhere in your code, either in class X or, if X is a precompiled class, in the caller's class, the compiler will create code to call getClass() on an instance of X, or call Class.forName("X"), and cache the result in a private static member.
As to when it was added: I believe it was a JDK 1.2 feature, but I could be wrong; it could have been 1.1. [ November 16, 2004: Message edited by: Ernest Friedman-Hill ]
Well, it could be, I suppose, but at the time they were adding it, old class files wouldn't have it, and new ones would, and so obviously that would be a mess. It was presumably easier to do it this way. Is there something you don't like about the way it's done?
This reminds me of the "length" pseudo-member in arrays, which I personally detest -- why wasn't it defined to be a method instead?
What I don't like is - class is not a member field at all but we use it as a member of all Objects. Also, why do we need this field when getClass() is there?
The members of an array type are all of the following:
The public final field length, which contains the number of components of the array (length may be positive or zero) The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions All the members inherited from class Object; the only method of Object that is not inherited is its clone method