说我有一个类和一个名为testMethod(String test1,String test 2)的方法。 我也有不同的方法,这将调用哪个方法永远是在另一个类见下动态调用方法名称
public class functional {
testMethod(String test1, String test2) {
reCallMethod();
}
}
reCallMethod(){
testMethod(test1, test2); // ------> This has to be dynamic. I've written the method name as "testMEthod" here. But I want it generalized so that I can use this in any method and not just in "testMethod"
}
更多的信息,例如:----------------- --------------
public class test1 {
public void TestCase1(String param1, String param2, String param3) {
try {
//Bla Bla Bla
}
catch (Throwable t) {
TestCase_Store_Locator_Verify_Page_Name(param1,param2,param3); //Retry running this method
}
}
}
public class test2 {
public void TestCase2(String param1, String param2, String param3, String param4, String Param5) {
try {
//Bla Bla Bla
}
catch (Throwable t) {
TestCase2(param1,param2,param3,param4,param5); //Retry running this method
}
}
}
像TestCase1和TestCase2我有500次测试。相反,上面做的,我将有一个名为retryLogic常用的方法如下面
public void retryLogic(){
//Call the test method in the class which this method is placed.
}
So my TestCase1 will look like
public class test1 {
public void TestCase1(String param1, String param2, String param3) {
try {
//Bla Bla Bla
}
catch (Throwable t) {
retryLogic(); //Retry running this method
}
}
}
public void TestCase2(String param1, String param2, String param3) {
try {
//Bla Bla Bla
}
catch (Throwable t) {
retryLogic(); //Retry running this method
}
}
}
它看起来像你正在寻找[反射](http://docs.oracle.com/javase/tutorial/reflect/member/methodInvocation.html)。 – Pshemo
它为什么会变成动态的? –
请注意,在java中,按照惯例,类名以大写字母开头,方法名以小写字母开头。大多数人都遵循这些惯例。 –