动态装载一个对象到是可以,像这样
myObject o = (myObject)Class.forName("myObject").newInstance();
方法就不知道,有的话告诉我,关注

解决方案 »

  1.   

    你可以试试public Method getMethod(String name,Class[] parameterTypes)
      

  2.   

    Method cMethod = clazz.getMethod(strMethodName, new java.lang.Class[]{parameterTypesClass});
    cMethod.invoke(object, new Object[]{parameter});
      

  3.   

    Method aMethod = getClass().getMethod(yourMethodName,null);
    aMethod.invoke(this,null);
      

  4.   

    Method cMethod = clazz.getMethod(strMethodName, new java.lang.Class[]{parameterTypesClass});
    cMethod.invoke(object, new Object[]{parameter});
    的说法是正确的,我再进一步解释一下:
    strMethodName是你要调用的方法名字,parameterTypesClass是你要调用的方法的参数的类型的数组,且必须声明为Class[]类型的数组!
    object:当你要调用的方法为static时,该参数为null,否则应该是你所要载入的类的实例(即该方法所属的类的实例)
    parameter:是你要调用的方法参数(与parameterTypesClass中的类型声明对应)
    谢谢!