[20] in java-interest
Re: Why is Java not more reflective?
daemon@ATHENA.MIT.EDU (Charles L. Perkins)
Tue Apr 25 23:31:51 1995
Date: Tue, 25 Apr 95 23:04:15 -0400
From: "Charles L. Perkins" <clp@home.HarvardSq.com>
To: java-interest@java.Eng.Sun.COM
> > (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)?
>
> Java supports the notion of interfaces. If you have an array of Printable
> objects (ie objects that implement the Printable interface) then you can
> print them, regardles of their actual type.
Arthur:
I think you misunderstood me. I would like to implement a method that passes
*any* message I specify to a set of objects. Suppose I want to send foo to a
Vector v of objects, then my only choice now is to write:
for (Enumeration e = v.elements; e.hasMoreElements(); )
e.foo();
over and over again in different places for each different message "foo." I'd
like to be able to say, e.g.:
v perform: "foo"
but Vector can't implement such a message since there is no way to dispatch
methods dynamically. This is a pretty common thing to want to do, and I just
wondered if there was some workaround you guys use in lieu of the above.
Charles
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com