A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© yshshe1700 初级黑马   /  2019-4-12 17:24  /  564 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

[AppleScript] 纯文本查看 复制代码
public class Game {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
        Class<?> c = Class.forName("cn.itcast.lh.Entry");//获取Class类的对象

        Constructor<?> con = c.getConstructor();

        Method m = c.getDeclaredMethod("begin");
        m.setAccessible(true);

        Object obj = con.newInstance();
        m.invoke(obj);
        Class<?> roo = Class.forName("cn.itcast.lh.Room");//获取Class对象

        Constructor<?> goo= roo.getDeclaredConstructor();//通过构造方法创建对象
        goo.setAccessible(true);
        Method te = roo.getDeclaredMethod("tellMe");//通过对象获取方法

        te.setAccessible(true);
        Object ob = goo.newInstance();
        te.invoke(ob);
        Method te1 = roo.getDeclaredMethod("tellMe", int.class);
        te1.setAccessible(true);
        Object ob1 = goo.newInstance();
        te1.invoke(ob1,24);

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马