× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi.

Yes reflection does work reasonably well performance wise in most JDK 1.3
environments I've tested.

Also, a simple way to add new behavior dynamically that MIGHT fit some
situations is just to use polymorphism with dynamic class loading by
name....
with an interface they all implement ...

public class Myclass implements Executable { ...

Executable has 1 method defined ( execute below)

All classes implement a common method ....

public Hashtable execute(String[] args) ...

Just dynamically instantiate a class to a

Executable exec = Class.forName("Myclass");
String s[] = new String[1];
s[1] = "hi";
java.util.Hashtable = exec.execute(s);

Here I've instantiated a brand new class,  passed parms, invoked the method
and received results all because the new class implemented the Executable
interface ...

For adding new behavior through new classes at runtime, polymorphism works
well....   This IS not full dynamic invocation similar to the reflection
package but can be useful in some circumstances

Jim Mason


Message text written by INTERNET:java400-l@midrange.com
>

> In traditional languages calling a run-time module is a natural feature.
For
> instance,
>
>                CALL    PROG
>
> RPG statement calls a program whose name is unknown at compilation time.

IKTAN, but your terminology is a bit imprecise.  In an ILE sense,
calling a "module" (more precisely, an 'entry point' in a module)
implies that some binding has occurred.  Now, this binding may
be early- (compile-time) or late- (run-time) bound, but calling
into a module is definitely different than calling a program.

> In Java a similar "dynamic" call is supported by RMI, but the performance
> penalty seems to be too high, especially if running a just simple servlet
> model. There is also Dynamic Invocation Interface, which is basically the
> same thing.

RMI is a lot more than a way to do dynamic calls.  RMI is a facility for
establishing cooperation between Java code running in separate JVMs.
This cooperation can get very involved, since it's effectively allowing
for the sharing of objects -- interactions and all -- between JVMs.
Pretty "gorpy" stuff, though those that use it around here use it to
good advantage.

For more of an "apples to apples" comparison, IMO, the RPG dynamic call
might be compared with the Runtime.exec() functionality of Java.

Runtime.exec() calls a program -- usually in a new process -- and makes
the program's execution status and I/O available to Java via the Process
object.

> Is there a better way? What I need is a preferably nice and simple way of
> invoking methods unknown at compilation time. It can also be assumed that
at
> compilation time I'm not aware of the class names either. What is the
most
> common way of doing this?

By "method" do you mean method of a Java objects?  How does your
application determine the name of the target class and method?

I'm not terribly well checked out on this, but IIRC one common paradigm is
to load up the class, and get an instance, with calls like:
     Class fooClz = Class.forName("some.class.name");
     MyClass myFoo = (MyClass) fooClz.newInstance();

...then using the reflection API to determine what methods are available:
     Method[] myMethods = fooClz.getMethods();

...or if you know the method name and signature:
     Method myMethod = fooClz.getMethod("methodName", new Class[] {
parm1_type.class, parm2_type.class...});

Once you have the Method object, you can invoke it using:
     myMethod.invoke(Object obj, Object[] parms)
interface...

Not sure what else to suggest.  Again, this area is one I'm hoping to learn
more about...  (Aren't they all ;-)

-blair

Blair Wyman -- iSeries JVM -- (507) 253-2891
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"I was born not knowing, and have had only a
little time to change that here and there."   -- Richard P. Feynman

<



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.