4 ms·
I guess I'm not sure what "object" means in Java, then. In languages I'm used to, an object is a type of value, and values are things that you can store in (or
by repsilat 8y ago
I guess I'm not sure what "object" means in Java, then.
In languages I'm used to, an object is a type of value, and values are things that you can store in (or refer to with) variables.
The only vaguely object-like feature of Java classes I can think of is that you can look up (static) methods/attributes on them with a dot.
Or is there more? You can't call `String.toString()`, so `String` isn't an instance of something that inherits from `Object`. I'm at a bit of a loss here... There obviously exist "class objects", but they're not normally what people refer to when they talk about classes. I'd say Java classes are almost purely lexical constructs (though I could be wrong there -- again, I don't know much about Java...)
- chrisseaton 8y ago> In languages I'm used to, an object is a type of value, and values are things that you can store in (or refer to with) variables. Class theStringClass = String.class; Class[] myArrayOfClasses = new Class[1]; myArrayOfClasses[0] = theStringClass; callSomeOtherMethod(theStringClass); > You can't call `String.toString()` String.class.toString() => "class java.lang.String" theStringClass.toString() => "class java.lang.String" myArrayOfClasses[0].toString() => "class java.lang.String" somethingThatReturnsAClass().toString() => "class java.lang.String" > `String` isn't an instance of something that inherits from `Object` Class theObjectClass = Object.class; theObjectClass.isAssignableFrom(theStringClass) => true > I'd say Java classes are almost purely lexical constructs They aren't - here's the source code for the Class class. https://github.com/Project-Skara/jdk/blob/c2105ced865fba11fbf8d4a8e18a59fcb1fe10fd/src/java.base/share/classes/java/lang/Class.java#L153 https://github.com/Project-Skara/jdk/blob/c2105ced865fba11fb... Here's the source code for the toString method we were calling https://github.com/Project-Skara/jdk/blob/c2105ced865fba11fbf8d4a8e18a59fcb1fe10fd/src/java.base/share/classes/java/lang/Class.java#L190-L193 https://github.com/Project-Skara/jdk/blob/c2105ced865fba11fb...