黑马程序员技术交流社区

标题: 【成都校区Javaee24期】 [打印本页]

作者: yshshe1700    时间: 2019-4-12 17:24
标题: 【成都校区Javaee24期】
[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);





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2