Classes are in some sense like objects, meaning they can hold their own state, but there is no notion of meta-classes like in Smalltalk.
The class in the JVM is like a module that holds functions and attributes. And the JVM byte-code is very class-centric.
The objects themselves are probably not what you think they are. The JVM currently has no notion of "call method next() on object O" ... that's done with something like ... invoke_virtual Enumerable.next(obj). The bytecode "invoke_virtual" is responsible for doing the single-dispatching (subtype-polymorphism) at runtime, otherwise it looks just like an invoke_static ... so the compiler is crucial for generating the correct byte-code, because the class has to be known at runtime ;)
Class c = [SomeRandomClass class];
id thingy = [[c alloc] init];
but Java won't let you do the equivalent: Class c = SomeRandomClass;
Object x = new c; Class c = SomeRandomClass.class;
Object x=c.newInstance();In Java's type system, classes are 'first class objects':
// unseen?
if (foo.getClass() instanceof someClassObject) ...You can't pass someClassObject as an argument to anything but an operator like new or instanceof, and you can't assign to or from it, it doesn't itself belong to a class. It isn't an object.
No. Its a variable assigned in runtime.
public void yesYouCan (Object foo, Class<?> someClassObject) {
// compile time?
if(foo.getClass() instanceof someClassObject) { ... }
}
Regardless, class and symbolic resolution occur at both compilation (to create the binary clsss files) and in runtime in the JVM (to load and execute the binary generated by the compiler):http://java.sun.com/docs/books/jls/second_edition/html/execu...
> You can't pass someClassObject as an argument to anything but an operator like new or instanceof, and you can't assign to or from it, it doesn't itself belong to a class. It isn't an object.
No, its quite possible/common to write methods that take class objects as parameters.
if(foo instanceof SomeClassObject) ...
or if(SomeClassObject.isInstance(foo)) ...