码迷,mamicode.com
首页 > 其他好文 > 详细

根据类名,方法名,反射调用类的方法

时间:2014-06-28 11:14:30      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   get      name   

/**
    * 根据类名,方法名,反射调用类的方法
   * @方法名称: getResult 
   * @描述: TODO 
   * @param className
   * @param methodName
   * @param params
   * @return
    */
   public static String getResult(String className,String methodName,Map<String,Object> params){
         
         String result = null;
         
         try{
         Object obj = Class.forName(className).newInstance();
         Class clazz = obj.getClass();  
         Method mothod = clazz.getDeclaredMethod(methodName, Map.class); 
          result = (String) mothod.invoke(obj, params); 
         }catch (Exception e) {
            e.printStackTrace();
        }
         return result;
     }

 

根据类名,方法名,反射调用类的方法,布布扣,bubuko.com

根据类名,方法名,反射调用类的方法

标签:style   blog   color   get      name   

原文地址:http://www.cnblogs.com/angryprogrammer/p/3798946.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!