看看java的反射机制和java.lang.class和java.lang.reflect包Constructor[] constructors = c.getDeclaredConstructors();

解决方案 »

  1.   

    public Function(String function,Object[] arg) throws Exception {
            sFunction = function;
            
            int i = function.lastIndexOf('.');        String classname = "com.justnorth.bc.report.functions."+function;        String methodname    ="getValue";
            Class  classinstance = null;
        
            try {
                classinstance = Class.forName(classname);
            } catch (Exception e) {
                throw e;
            }
            Class[] parameterTypes=new Class[arg.length];
            for(i=0;i<parameterTypes.length;i++){
                parameterTypes[i]=arg[i].getClass();
                System.out.println(parameterTypes[i]);
            }
            //测试传过来的雷的构造函数的参数类型        
    //        Constructor cs[]=classinstance.getDeclaredConstructors() ;
    //        for(int j=0;j<cs.length;j++){
    //            Class[] p=cs[j].getParameterTypes();
    //            for(i=0;i<p.length;i++){
    //                System.out.println(p[i]);
    //            }
    //        }
            
            Constructor construct=classinstance.getConstructor(parameterTypes);
            
            functionInstance=construct.newInstance(arg);
            mMethod=classinstance.getMethod(methodname,new Class[0]);
        }
      

  2.   

    A 调用B
    1.A中
     B test =new B("参数1","参数2")
    2.B中
     你怎么接都可以底!!!
      

  3.   

    问题就处在构造方法的参数是基本类型。
    我们知道Class.getConstructor(Class[])和Constructor.newInstance(Object[]),所以你直接传入int[]是不行的。关于这样有基本类型的构造我们这样做(使用基本类型对应类中的static TYPE):    Class[] paramTypes = {Integer.TYPE, Integer.TYPE};
        Object[] params = {new Integer(i), new Integer(j)};
        Constructor con = Class.forName(className).getConstructor(paramTypes);
        CCC c = (CCC)con.newInstance(params);这样就解决了。
      

  4.   

    你的参数是哪个类的,就Class.forName("哪个类");
      

  5.   

    类名:com.aaa.CCC,已知其构造函数CCC(int,int)String className = "com.aaa.CCC";
    Class[] param = {Integer.TYPE, Integer.TYPE};
    int[] temp = {1, 2};
    CCC c = (CCC)CCC.class.getConstructor(param).newInstance(temp);