說我有一個類和一個名爲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中,按照慣例,類名以大寫字母開頭,方法名以小寫字母開頭。大多數人都遵循這些慣例。 –