zoukankan      html  css  js  c++  java
  • 反射执行方法

     

    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;
        
    }
    
    }
    
    
    一万年太久,只争朝夕!
  • 相关阅读:
    表操作
    mysql表的完整性约束
    mysql支持的数据类型
    数据库存储引擎
    Navicat工具、pymysql模块、数据备份
    数据库一
    IO模型
    协成
    线程
    进程
  • 原文地址:https://www.cnblogs.com/chaoba/p/6895571.html
Copyright © 2011-2022 走看看