[10] in java-interest

home help back first fref pref prev next nref lref last post

Why is Java not more reflective?

daemon@ATHENA.MIT.EDU (Charles L. Perkins)
Fri Apr 21 14:27:18 1995

Date: Fri, 21 Apr 95 13:17:28 -0400
From: "Charles L. Perkins" <clp@home.HarvardSq.com>
To: java-interest@java.Eng.Sun.COM

> > The C support code for the java Tcl Interpreter makes a dynamic method 

> > call via the routine execute_java_dynamic_method. 

> > 

> > Is there a way to do the same thing directly in java or can it only be 

> > done in C?
> It can only be done from C.

To the Java design team:

I am assuming from the above (and from the complete lack of "reflective"
features being mentioned in the Java language spec.) that one cannot call
an explicit Java method at runtime.  Given that the runtime already has
the necessary method dictionaries and class structures, I was wondering
why this restriction was made. [I can think of several reasons myself, but
I'd like to know your rationale(s).]

Also, how does one "work around" the following needs in Java:

(1) A method wants to call upon several others objects to aid it in jobs that
require callbacks back into itself;  if it wants to have several simultaneous
callbacks outstanding, using the same name for the callback methods involves
discriminating the sender at runtime (clumsy and annoying).  Without the
anonymous methods of Lisp or the "perform:" message in Smalltalk, how does
one achieve a similar result?

(2) Even more disturbing is trying to use delegation of various kinds.  The
simplest problem is trying to re-send a message to a different receiver after
catching a NoSuchMethod exception (useful for implementing unusual but very
flexible object models or for "standing in" for another object and then
passing along all the messages you don't understand to it).

(3) Finally, what about sending an arbitrary message to an Array of objects?
Without "perform:" you have to explicitly loop each time and send it by hand.
Is there a better way to implement this (and even more complex control and
iteration paradigms)?

One simple thought exercise shows a case where reflective features are quite
nice:  you have an interactive environment that displays objects visually.
When selected, you can type in a simple message to send to the object.  Even
being able to enumerate message names and providing a list of "understood"
messages would be better than nothing in this case, but even that is not
possible within the current paradigm, correct?

Are you simply thinking that all such "complex" Java environments will have
to include the full compiler?

I'd like as many Java people to respond as have the time, for a feel the spec.
does not express the intentions and goals for the language as well as it might,
and I'd like to get a better sense of them from you.
							    Charles L. Perkins
							    Virtual Rendezvous

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post