Advertisement

12.19.2006 at 07:29AM PST, ID: 22097952
[x]
Attachment Details

Dynamic method calls - invoking methods at need

Asked by DenisPalas in Java Programming Language

Tags: from, method, programming

Dear All


I have an array which holds method names and parameters as shown in array Functionstest. According to different conditions that happen in the program, my program will choose a specific row from array and build a string (like string1) that will be the method and parameters it needs to execute.

After building the string , how do I execute the related method ? For example, after building string2, how do I invoke the method plus1 that will actually execute it?


Thanks
Denis



public class TestClass {

public static void main(String[] args) throws Exception

{
Calling method solvethis(parameters)
}



public int solvethis (parameters)  {

String Functionstest[][]= {
                    {"Mult1","Var1","Var2","Var3"},
                    {"Plus1","Var1","Var2"},
                    {"FindPrice","Var1","Var2","Var3","Var4"},
                    {"FindCosine","Var1"}
                   };

// I go through each row of my array and make up a string like :

String1= "Mult1(Var1,Var2,Var3)"
String2="Plus1(Var1,Var2)"
String3="FindPrice(Var1,Var2,Var3,Var4)"
String4="FindCosine(Var1)"

}


// Methods that will carry out the different functions

public int Mult1(int Var1,int Var2, int Var3)

{
}

public int Plus1(int Var1,int Var2)
{
}

public int FindPrice1(int Var1,int Var2, int Var3, int Var4)
{
}


} // End classStart Free Trial
[+][-]12.19.2006 at 08:40AM PST, ID: 18166897

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 08:41AM PST, ID: 18166907

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 08:47AM PST, ID: 18166946

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 08:48AM PST, ID: 18166956

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 08:49AM PST, ID: 18166966

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 08:51AM PST, ID: 18166984

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 09:01AM PST, ID: 18167059

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 09:04AM PST, ID: 18167085

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 09:11AM PST, ID: 18167146

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.19.2006 at 09:30PM PST, ID: 18171511

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.21.2006 at 07:28AM PST, ID: 18180991

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.21.2006 at 07:51AM PST, ID: 18181152

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.21.2006 at 10:03AM PST, ID: 18182064

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Java Programming Language
Tags: from, method, programming
Sign Up Now!
Solution Provided By: pkwan
Participating Experts: 4
Solution Grade: A
 
 
[+][-]12.21.2006 at 10:05AM PST, ID: 18182082

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32