Live data from Hacker News

Java Was Strongly Influenced by Objective-C

cs.gmu.edu

51–53 of 53 posts

Re: Java Was Strongly Influenced by Objective-C

#51
post #38

Earlier quoted context omitted.

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.

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;

  Class c = SomeRandomClass.class;
  Object x=c.newInstance();

Re: Java Was Strongly Influenced by Objective-C

#52
post #9
post #7

Don't Classes in Java get boiled off in the compiler? There are no "class objects" at runtime that I've ever seen.

// unseen? if (foo.getClass() instanceof someClassObject) ...

  if(foo instanceof SomeClassObject) ...
or

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

Re: Java Was Strongly Influenced by Objective-C

#53

Earlier quoted context omitted.

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;

Class c = SomeRandomClass.class; Object x=c.newInstance();

Yes, but that's making use of runtime magic (the Class class) which isn't used outside metaprogramming.
Post reply on HN