Here you can find the source of loadClass(String classname, Class clazz)
Parameter | Description |
---|---|
classname | Desired class. |
clazz | Class object used to obtain a class loader if no context class loader is available. |
public static Class loadClass(String classname, Class clazz) throws ClassNotFoundException
//package com.java2s; //License from project: LGPL public class Main { /**/*from ww w. j a v a 2s .co m*/ * Tries to load the class from the current thread's context class loader. If * not successful, tries to load the class from the current instance. * @param classname Desired class. * @param clazz Class object used to obtain a class loader * if no context class loader is available. * @return Class, or null on failure. */ public static Class loadClass(String classname, Class clazz) throws ClassNotFoundException { 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); } }