Nyimi Jose wrote:

> Like in Perl, "Reflection" is also possible in Java:
> 
> 
http://developer.java.sun.com/developer/technicalArticles/ALT/Reflection/index.html
> 
> Specially the following section interested me :
> 
> Invoking Methods by Name
> 
> So far the examples that have been presented all relate to obtaining class
> information. But it's also possible to use reflection in other ways, for
> example to invoke a method of a specified name.
> 
> To see how this works, consider the following example:
> 
>    import java.lang.reflect.*;
>         
>    public class method2 {
>       public int add(int a, int b)
>       {
>          return a + b;
>       }
>         
>       public static void main(String args[])
>       {
>          try {
>            Class cls = Class.forName("method2");
>            Class partypes[] = new Class[2];
>             partypes[0] = Integer.TYPE;
>             partypes[1] = Integer.TYPE;
>             Method meth = cls.getMethod(
>               "add", partypes);
>             method2 methobj = new method2();
>             Object arglist[] = new Object[2];
>             arglist[0] = new Integer(37);
>             arglist[1] = new Integer(47);
>             Object retobj
>               = meth.invoke(methobj, arglist);
>             Integer retval = (Integer)retobj;
>             System.out.println(retval.intValue());
>          }
>          catch (Throwable e) {
>             System.err.println(e);
>          }
>       }
>    }
> 

reflection has been there for a while (i suppose the dynamic proxy thing is 
new to Java2 v1.3 or 1.4) ever since JavaBean hits the street. it's one of 
the primary (along with object serialization) reason why the IDE env. can 
find and load your JavaBean components. i am not too familiar with dynamic 
proxy to give advantages (or disadvantages) over one or the other but 
reflection does seem like another path for doing the dynamic method 
invocation in Perl.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to