用JAVA的反射机制
建立一个接口或是一个抽象类来实现,否则实现反射机制用处不大

解决方案 »

  1.   

    你的意思是不是说将某些类名存入到一个数据表中,然后在要用这个类的时候将这各类名检索出来实例化,再用它的方法?
    如果这样的话,你用reflect将这些类存入一个list中,最后转型取出不就行了?
      

  2.   

    从数据库取就不用说了Class c = Class.forName("baseform");      
    c.getMethod("getaction", new Class[] {null}).invoke(c.newInstance());
      

  3.   

    Java Reflection-JAVA反射
    详见我的Blog
    http://www.nihaoblog.com/1_2524.html
      

  4.   

    做个修改,假设方法getaction(),无参数Class c = Class.forName("baseform");      
    c.getMethod("getaction", new Class[] {}).invoke(c.newInstance());
      

  5.   

    ClassA是实现了接口1的类
    Class forClass = Class.forName("com.ClassA");
    接口1 接口实例 = (接口1) forClass.newInstance();
      

  6.   

    Class c = Class.forName("baseform");      
    实例化就好了.
      

  7.   

    这些偶都明白了,使用getDeclaredMethod 能获得对应类的方法列表,可是偶想知道这个方法带传入参数该怎么给他传进去丫,还望各位大哥教偶~
      

  8.   

    invoke(Object obj, Object[] args)
      

  9.   

    Class test=new Class();
    test = this.getClass().getClassLoader().loadClass(formClassName).newInstance();
    method [] = test.getDeclaredMethod("producttablehandle",public);然后如何传入参数?
      

  10.   

    method [] = test.getDeclaredMethod("producttablehandle",public);
    应该改为:
    method [0] = test.getDeclaredMethod("producttablehandle",public);sorry
      

  11.   

    method[0].invoke(test, 要传入的参数数组);
                          ------------
                          Object[] args
                           
                          具体传什么只有你知道了,谁知道你的函数参数是什么
      

  12.   

    Class c = Class.forName(formClassName);
    HashMap hm = new HashMap();
    hm.put("kingfish", "八百里秦川@龙城异客");
    Object[] objs = new Object[1];
    objs[0] = hm;
    Object o =  c.getMethod("producttablehandle", new Class[] {HashMap.class}).invoke(c.newInstance(),objs);