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

反射执行方法

时间:2017-05-23 19:46:51      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:ring   style   color   rgs   new   code   get   log   method   

笨笨 以爱之名,只为遇见你! 阿正

package Fanshe;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.util.ArrayList;

import utils.Conn;

public class FConn {
    public static void main(String[] args) throws Exception {

        FConn.fConn1(Conn.class);

    }

    public static <T> ArrayList<T> fConn(Class<T> obj) throws Exception {
     Constructor<?> cons = obj.getDeclaredConstructor();
        T newInstance = obj.newInstance();
        Method method = obj.getMethod("link", new Class[] {});
        method.invoke(newInstance, null);

        return null;
    }





public static <T> ArrayList<T> fConn1(Class<T> obj) throws Exception {
    
    T newInstance = obj.newInstance();
    Method m= obj.getDeclaredMethod("link");
    m.invoke(newInstance);
    
    
    return null;
    
}

}


 

反射执行方法

标签:ring   style   color   rgs   new   code   get   log   method   

原文地址:http://www.cnblogs.com/chaoba/p/6895571.html

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