Hacker News new | ask | show | jobs
by blasdel 5970 days ago
In this case isn't someClassObject just a literal that's resolved at compile-time and erased into a simple identifier symbol?

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.

1 comments

> In this case isn't someClassObject just a literal that's resolved at compile-time and erased into a simple identifier symbol?

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.