Class类说明

  1. 获取Class对象的三个方法
    使用Object的getClass()方法
    Class.forName("类的全限定名")
    直接写A.class / int.class

  2. Class类的常用方法说明
    getName():
    getSimpleName():
    getSuperClass():
    isArray(): 判断是不是数据类型
    getComponentType(): 数组类型
    newInstance():
    getClassLoader():

  3. forName() 方法说明

 public static Class forName(String className)
                throws ClassNotFoundException {
        // 获取调用者的class
        Class caller = Reflection.getCallerClass();
        // initialize 默认为 true, 或初始化类
        return forName0(className, true, ClassLoader.getClassLoader(caller), caller);
    }


public static Class forName(String name, boolean initialize,
                                   ClassLoader loader)
        throws ClassNotFoundException
    {
        Class caller = null;
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            // Reflective call to get caller class is only needed if a security manager
            // is present.  Avoid the overhead of making this call otherwise.
            caller = Reflection.getCallerClass();
            if (sun.misc.VM.isSystemDomainLoader(loader)) {
                ClassLoader ccl = ClassLoader.getClassLoader(caller);
                if (!sun.misc.VM.isSystemDomainLoader(ccl)) {
                    sm.checkPermission(
                        SecurityConstants.GET_CLASSLOADER_PERMISSION);
                }
            }
        }
        return forName0(name, initialize, loader, caller);
    }

https://blog.csdn.net/fengyuzhengfan/article/details/38086743

你可能感兴趣的:(Class类说明)