News for hackers. Stuff that matters.
Re:Java Was Strongly Influenced by Objective-C by blasdel on Thursday February 11, 2010 @06:02PM (#1119032)
Don't Classes in Java get boiled off in the compiler? There are no "class objects" at runtime that I've ever seen.
Re:Java Was Strongly Influenced by Objective-C by bad_user on Thursday February 11, 2010 @06:29PM (#1119100)
What do you mean?

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 ;)

Re:Java Was Strongly Influenced by Objective-C by pvg on Thursday February 11, 2010 @06:24PM (#1119088)
There are. Think about classloaders and the whole dynamic code loading thing. Every single object has a class object associated with it.
Re:Java Was Strongly Influenced by Objective-C by blasdel on Thursday February 11, 2010 @08:09PM (#1119361)
But can you pass classes around as objects after they're loaded? Do they have a value beyond their identifier?
Re:Java Was Strongly Influenced by Objective-C by pvg on Thursday February 11, 2010 @09:22PM (#1119537)
Yep, you can pass them around, they do have values, in fact, they can have different values for the same type sometimes. This has been the case since well before Java even had reflection - having them around is fairly central to the Java dynamic loading and security model.
Re:Java Was Strongly Influenced by Objective-C by dminor on Thursday February 11, 2010 @08:41PM (#1119445)
Yes, although Java's reflection is somewhat of a pain in the ass and limited in many ways. But you can take a Class object and call newInstance(), and it will invoke the class's no-arg constructor.
Re:Java Was Strongly Influenced by Objective-C by duskwuff on Thursday February 11, 2010 @08:58PM (#1119490)
Moreover, reflection is less of a language feature and more of a very low-level library feature. In ObjC, one can write

    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;
Re:Java Was Strongly Influenced by Objective-C by vlisivka on Friday February 12, 2010 @03:57AM (#1120116)

  Class c = SomeRandomClass.class;
  Object x=c.newInstance();
Re:Java Was Strongly Influenced by Objective-C by duskwuff on Saturday February 13, 2010 @03:37PM (#1123506)
Yes, but that's making use of runtime magic (the Class class) which isn't used outside metaprogramming.
Re:Java Was Strongly Influenced by Objective-C by lucifer on Thursday February 11, 2010 @10:17PM (#1119643)
When you define a class, say "Foo", instances of Foo are Foo objects. "Foo", itself, is an instance of a class named "Class" which is a direct descendent of the class "Object".

In Java's type system, classes are 'first class objects':

http://en.wikipedia.org/wiki/First-class_object

Re:Java Was Strongly Influenced by Objective-C by lucifer on Thursday February 11, 2010 @06:04PM (#1119039)

    // unseen?
    if (foo.getClass() instanceof someClassObject) ...
Re:Java Was Strongly Influenced by Objective-C by blasdel on Thursday February 11, 2010 @08:18PM (#1119384)
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.

Re:Java Was Strongly Influenced by Objective-C by lucifer on Thursday February 11, 2010 @10:02PM (#1119605)
> 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.

Re:Java Was Strongly Influenced by Objective-C by vlisivka on Friday February 12, 2010 @04:07AM (#1120124)

  if(foo instanceof SomeClassObject) ...
or

  if(SomeClassObject.isInstance(foo)) ...