import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class ReflectionAPI {
public static void main(String[] args) throws SecurityException, NoSuchMethodException {
// TODO Auto-generated method stub
String x = "sampleTest";
Method method=ReflectionAPI.class.getMethod(x, String.class);
method.invoke(method, "hello");
System.out.println("end");
}
public static void sampleTest(String x){
System.out.println("in sample test -- "+x);
}
}
use this
[code:1x0ojny1]package com.sample;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class ReflectionAPI {
public static void main(String[] args) throws SecurityException,
NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// TODO Auto-generated method stub
String x = "sampleTest";
Method method = ReflectionAPI.class.getMethod(x, String.class);
method.invoke(method, "hello");
System.out.println("end");
}
public static void sampleTest(String x) {
System.out.println("in sample test -- " + x);
}
}
[/code:1x0ojny1]
It still gives same error on getMethod:
The method getMethod(String, Class[]) in the type Class is not applicable for the arguments (String, Class)