import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class testlinux{
public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
int functionnameparam=4;
String str1="Goodmorning",str2=" guys";
Method method=testlinux.class.getDeclaredMethod("methodcall"+functionnameparam, String.class);//here we passing String.class because we are passing String type arguments in below method,if you need to pass other type(int/long etc) update according to your class.
method.invoke(new Object(),str);//this is same as calling "methodcall4(str1);"
method.invoke(new Object(),str1+"/"+str2);//this is same as calling "methodcall4(str1+"/"+str2);"
}
public static void methodcall4(String mergedstr1andstr2) {
System.out.println("str= "+mergedstr1andstr2);
}
}
import java.lang.reflect.Method;
public class testlinux{
public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
int functionnameparam=4;
String str1="Goodmorning",str2=" guys";
Method method=testlinux.class.getDeclaredMethod("methodcall"+functionnameparam, String.class);//here we passing String.class because we are passing String type arguments in below method,if you need to pass other type(int/long etc) update according to your class.
method.invoke(new Object(),str);//this is same as calling "methodcall4(str1);"
method.invoke(new Object(),str1+"/"+str2);//this is same as calling "methodcall4(str1+"/"+str2);"
}
public static void methodcall4(String mergedstr1andstr2) {
System.out.println("str= "+mergedstr1andstr2);
}
}
Comments
Post a Comment