I found some posts about java/reflection on this site. But still can't understand something. Could anyone tell where's error in my code? (need to print "HELLO!")
Output:
java.lang.NoSuchMethodException: Caller.foo()
Here's my Main.java:
import java.lang.reflect.*;
class Main {
public static void main(String[] args) {
Caller cal = new Caller();
Method met;
try {
met = cal.getClass().getMethod("foo", new Class[]{});
met.invoke(cal);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
class Caller {
void foo() {
System.out.println("HELLO!");
}
}