import org.apache.commons.beanutils.MethodUtils;
public class subscriber
{
public calculator cal=new calculator();
String funcName = "";
int result;
public void getValues(String strfuncName)
{
funcName= strfuncName; //has the function name of class calculator
}
public void giveResult()
{
result=cal.funcName();
//i want it to call the function whose name is stored in funcName
}
}
리플렉션을 사용하고 org.apache.commons.beanutils.MethodUtils
가져 오기를 사용하는 방법 그리고 함수 호출이 동적 일 수 있으므로 함수를 호출 할 수 있으므로 미리 정의 할 수 없습니다.
Method method = obj.getClass().getMethod("Methodname", new Class[] {});
String output = (String) method.invoke(obj, new Object[] {}); // String return type here, Sorry i mean yourType is your return type..
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다