take a look at my code….
Class<?> c = Class.forName("PerformanceInvokeService");
Method m = c.getDeclaredMethod("monthlyTestCal", new Class[] {
String.class, Date.class });
Object ret = m.invoke("PerformanceInvokeService", new Object[] {
"some string", new Date() });
System.out.println(ret);
i execute this and its thrown an exception
java.lang.IllegalArgumentException: object is not an instance of declaring class
i think, because i don’t create an instance of c (likes…new PerformanceInvokeService())
and i don’t know how to create it
somebody help?
sorry for my english…
thanks
If
PerformanceInvokeServicehas an accessible default constructor, you can create a new instance using:You can then pass that to the method invocation:
If there is no accessible default constructor, then you’ll have to find a constructor that you can use by using reflection.