学习链接 :

JAVA反射、慕课视频教程

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

JAVA反射、结合小的 Demo 讲解

JAVA反射、动态加载类

JAVA 的反射机制 随笔 第1张
package Learn;


public class Main {

    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
            try {
                Class c = Class.forName(args[0]);
                Stand stand = (Stand) c.newInstance();
                stand.start();
            } catch (ClassNotFoundException e) {
                System.err.println("something is wrong!!!");
                e.printStackTrace();
            }
    }
}

interface Stand{
    void start();
}

class B implements Stand{
    private int i = 0;
    public void start() {
        System.out.println(i);
        System.out.println("B...start");
    }
    
}

class C implements Stand{
    public void start() {
        System.out.println("C...start");
    }
}
动态加载类

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄