Results 1 to 2 of 2
  1. #1
    kiran2608 is offline Member
    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Default Invoking the Java Method with parameters dynamically

    Hi,


    I have a String with class name stored in it.

    className = "com.help."+className;

    I also have a string with method name to be invoked.

    methodName="getAmount";


    Class<?> c = Class.forName(className);

    Object o = c.newInstance();

    I have a method getAmount(int , double) in the class.

    How to invoke the method and pass the values to get a return value.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Invoking the Java Method with parameters dynamically

    See Reflection and the Method class.

Similar Threads

  1. Invoking a method
    By Brainz in forum New To Java
    Replies: 6
    Last Post: 12-06-2010, 02:07 PM
  2. Replies: 5
    Last Post: 11-21-2010, 02:08 PM
  3. Replies: 2
    Last Post: 10-24-2010, 04:34 PM
  4. Invoking method from String
    By Supamagier in forum Advanced Java
    Replies: 12
    Last Post: 05-29-2009, 09:21 AM
  5. Replies: 0
    Last Post: 04-23-2008, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •