public Object createValue(final UIDefaults table) { // In order to pick up the security policy in effect at the // time of creation we use a doPrivileged with the // AccessControlContext that was in place when this was created. if (acc == null && System.getSecurityManager() != null) { throw new SecurityException("null AccessControlContext"); } return AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { try { Class<?> c; Object cl; // See if we should use a separate ClassLoader if (table == null || !((cl = table.get("ClassLoader")) instanceof ClassLoader)) { cl = Thread.currentThread(). getContextClassLoader(); if (cl == null) { // Fallback to the system class loader. cl = ClassLoader.getSystemClassLoader(); } } ReflectUtil.checkPackageAccess(className); c = Class.forName(className, true, (ClassLoader)cl); SwingUtilities2.checkAccess(c.getModifiers()); if (methodName != null) { Class[] types = getClassArray(args); Method m = c.getMethod(methodName, types); return MethodUtil.invoke(m, c, args); } else { Class[] types = getClassArray(args); Constructor constructor = c.getConstructor(types); SwingUtilities2.checkAccess(constructor.getModifiers()); return constructor.newInstance(args); } } catch(Exception e) { // Ideally we would throw an exception, unfortunately // often times there are errors as an initial look and // feel is loaded before one can be switched. Perhaps a // flag should be added for debugging, so that if true // the exception would be thrown. } return null; } }, acc); }
c = Class.forName(className, true, (ClassLoader)cl);是有类加载器的,这也就拓展了能用的类的范围了