获取Class对象
作者:互联网
package reflect;
import pass.User;
/**
* @Author: DengJia
* @Date: 2021/12/1 9:15
* @Description: 获取Class对象的四种方式
*/
public class MainTest {
public static void main(String[] args) throws ClassNotFoundException {
User u = new User();
// 1.
Class<User> uC1 = User.class;
// 2.
Class<?> uC2 = Class.forName("top.dj.User");
// 3.
Class<? extends User> uC3 = u.getClass();
// 4.
Class<?> uC4 = ClassLoader.getSystemClassLoader().loadClass("top.dj.User");
}
}
标签:dj,对象,top,Class,获取,User,class,public 来源: https://www.cnblogs.com/DJOSIMON/p/15627503.html