Yes ! $obj->$method($args); Seems to be equivalent to this in Java: Object retobj = meth.invoke(methobj, arglist);
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); } } } Suppose that a program wants to invoke the add method, but doesn't know this until execution time. That is, the name of the method is specified during execution (this might be done by a JavaBeans development environment, for example). The above program shows a way of doing this. getMethod is used to find a method in the class that has two integer parameter types and that has the appropriate name. Once this method has been found and captured into a Method object, it is invoked upon an object instance of the appropriate type. To invoke a method, a parameter list must be constructed, with the fundamental integer values 37 and 47 wrapped in Integer objects. The return value (84) is also wrapped in an Integer object. José. > -----Original Message----- > From: david [mailto:[EMAIL PROTECTED]] > Sent: Thursday, January 30, 2003 11:09 PM > To: [EMAIL PROTECTED] > Subject: RE: Perl OO - Dynamic method call > > > Nyimi Jose wrote: > > > Just find out that Java provides something similar but not > simple (for > > me > > :) ) For those who are interested: > > http://java.sun.com/j2se/1.3/docs/guide/reflection/proxy.html > > > > Ok, I stop bothering you all those Java stuff, sorry ;) > > > > good reading! i wasn't aware of the Dynamic Proxy mechanism > in Java. that's > exactly what i was referring to in another post where Java > must resolve all method calls during compile time. > apparently, with dynamic proxy, this is no > longer the case. > > david > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > **** DISCLAIMER **** "This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer". Thank you for your cooperation. For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]