try { // 访问这个类 Class cls = Class.forName(classname); //调用main方法 Method main = cls.getMethod(“main”, new Class[] { String[].class }); main.invoke(null, new Object[] { new String[0] }); }catch (SecurityException se) { debug(“access to the information is denied:” + se.toString()); }catch (NoSuchMethodException nme) { debug(“a matching method is not found or if then name is or : ” + nme.toString()); }catch (InvocationTargetException ite) { debug(“Exception in main: ” + ite.getTargetException()); }catch (Exception e){ debug(e.toString()); }
在指定方法时我们只需要知道方法参数的类型,所以使用Class
调用方法时我们必须传递给方法一个实际的对象,所以使用Object
T1[] o={...}
T2[] o= {...}
有什么区别啊?
java.lang.Object
|
+--java.lang.Class
就是说,Class继承Object,是Object的子类。