or, alternatively, without downcasting you may call Class.getDeclaredMethods, find the one you want to invoke, and activate Method.invoke as you would do when writing a generic Dynamic Proxy. zm.
-----Original Message----- From: A mailing list for discussion about Sun Microsystem's Java Servlet API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Ankur Jain Sent: Friday, January 25, 2002 7:36 AM To: [EMAIL PROTECTED] Subject: Re: Need help with forName() for calling the method use the following code... i.e. Type cast the Object you created and call the method. ((Ext1)o).returnSomething(); Thanks Ankur Puneet Mathur <[EMAIL PROTECTED] To: [EMAIL PROTECTED] .AU> cc: Sent by: "A mailing Subject: Need help with forName() list for discussion about Sun Microsystem's Java Servlet API Technology." <SERVLET-INTEREST@JAV A.SUN.COM> 25/01/2002 10:55 AM Please respond to "A mailing list for discussion about Sun Microsystem's Java Servlet API Technology." Hi all I need help with dynamically loading classes using the forName(..) method of Class. I have a servlet which gets a 'application name' as a parameter - 'application name' is nothing but name of a Java class. Say the 'application name' is "Ext1", we have a class called 'Ext1.class' containing a set of methods. public class Ext1 { public static String returnSomething(String sParam1) { return "return from Ext1.returnSomething() with argument=" + sParam1; } } Now, my servlet contains the following code: .... import java.lang.reflect.*; .... String sApplName = "Ext1"; Class c = Class.forName (sApplName); Object o = c.newInstance(); Now, I want to invoke 'returnSomething(..)' method and get the return string value. How do I do it? Any help will be highly appreciated. Thanks in advance. Puneet ([EMAIL PROTECTED]) ********************************************************************** ***** IMPORTANT INFORMATION ***** This document should be read only by those persons to whom it is addressed and its content is not intended for use by any other persons. If you have received this message in error, please notify us immediately. Please also destroy and delete the message from your computer. Any unauthorised form of reproduction of this message is strictly prohibited. St.George is not liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt. ********************************************************************** ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html -----------------------Disclaimer------------------------ The views of the author may not necessarily reflect those of the Company. All liability is excluded to the extent permitted by law for any claims arising as a result of the use of this medium to transmit information by or to IT Solutions (India) Pvt. Ltd. We have taken precautions to minimize the risk of transmitting software viruses, but we advise you to carry out your own virus checks on any attachment to this message. We cannot accept liability for any loss or damage caused by software viruses. ------------------------Disclaimer------------------------ ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
