List of utility methods to do Class Load
Class | loadClass(String classname, Class clazz) Tries to load the class from the current thread's context class loader. ClassLoader loader; try { loader = Thread.currentThread().getContextClassLoader(); if (loader != null) { return Class.forName(classname, false, loader); } catch (Throwable t) { if (clazz != null) { try { loader = clazz.getClassLoader(); if (loader != null) { return Class.forName(classname, false, loader); } catch (Throwable t) { try { loader = ClassLoader.getSystemClassLoader(); if (loader != null) { return Class.forName(classname, false, loader); } catch (Throwable t) { throw new ClassNotFoundException(classname); |
Class | loadClass(String classname, Class clazz) Tries to load the class from the current thread's context class loader. ClassLoader loader; try { loader = Thread.currentThread().getContextClassLoader(); if (loader != null) { return loader.loadClass(classname); } catch (Throwable t) { if (clazz != null) { try { loader = clazz.getClassLoader(); if (loader != null) { return loader.loadClass(classname); } catch (Throwable t) { try { loader = ClassLoader.getSystemClassLoader(); if (loader != null) { return loader.loadClass(classname); } catch (Throwable t) { throw new ClassNotFoundException(classname); |
Class | loadClass(String classname, Class clazz) load Class return getClassLoader(clazz).loadClass(classname);
|
Class> | loadClass(String className, Class> context, boolean checkParent) Loads a class from the classloader; If not found, the classloader of the context class specified will be used. Class<?> clazz = null; try { clazz = Thread.currentThread().getContextClassLoader().loadClass(className); } catch (ClassNotFoundException e) { if (context != null) { ClassLoader loader = context.getClassLoader(); while (loader != null) { try { ... |
Class extends T> | loadClass(String className, Class Loads and returns the class named className of type superClass. try { Class<?> clazz = Class.forName(className); if (ofType == null || !ofType.isAssignableFrom(clazz)) { throw new IllegalArgumentException( "Class " + className + " must extend or implement " + ofType + "!"); return (Class<? extends T>) clazz; } catch (ClassNotFoundException cnfe) { ... |
Class | loadClass(String className, Class load Class return loadClass(className, targetType, false, cl);
|
Class extends T> | loadClass(String className, Class Load a class of a particular type. try { ClassLoader loader = type.getClassLoader(); if (loader == null) { loader = Thread.currentThread().getContextClassLoader(); Class<?> clazz = loader.loadClass(className); if (!type.isAssignableFrom(clazz)) { throw new RuntimeException("Class [" + clazz + "] is not a [" + type + ']'); ... |
Class> | loadClass(String className, ClassLoader cl) load Class if (cl != null) { try { return cl.loadClass(className); } catch (ClassNotFoundException ex) { return null; |
Class> | loadClass(String className, ClassLoader classLoader) load Class Class<?> objectClass; try { objectClass = Class.forName(className); } catch (ClassNotFoundException e) { if (classLoader != null) { objectClass = classLoader.loadClass(className); } else { throw e; ... |
Class> | loadClass(String className, ClassLoader classLoader) load Class return Class.forName(className, true, classLoader);
|