From "Primitive Data Types": "Primitive types are special data types built into the language; they are not objects created from a class." That, in turn, means that no, int
doesn't inherit from java.lang.Object in any way because only "objects created from a class" do that. Consider:
int x = 5;
In order for the thing named x
to inherit from Object, that thing would need to have a type. Note that I'm distinguishing between x
itself and the thing it names. x
has a type, which is int
, but the thing named x
is the value 5, which has no type in and of itself. It's nothing but a sequence of bits that represents the integral value "5". In contrast, consider:
java.lang.Number y = new java.lang.Integer(5);
In this case, y
has the type Number, and the thing named y
has the type Integer. The thing named y
is an object. It has a distinct type irrespective of y
or anything else.
Object
, actually returnint
? If yes, then, how can I get theint
back fromObject
in the calling environment? – Ergot