Here you can find the source of loadClass(final String className, final ClassLoader classLoader)
Parameter | Description |
---|---|
name | The name of the class to load. |
classLoader | The class loader with which to load the class; if null, the current thread's context class loader will be used. |
static Class<?> loadClass(final String className, final ClassLoader classLoader)
//package com.java2s; public class Main { /**//from ww w. j a va 2s. c o m * Tries to load the class with the given name. * <p> * This method uses the specified {@link ClassLoader} (or the current thread's * context class loader if {@code null} was passed as the {@code classLoader} * parameter. If the class cannot be found no exception is thrown but * {@code null} is returned instead. * </p> * <p> * This method is a stripped down version of the {@code loadClass} method in * SciJava-common's {@code ClassUtils} class. * </p> * * @param name The name of the class to load. * @param classLoader The class loader with which to load the class; if null, * the current thread's context class loader will be used. */ static Class<?> loadClass(final String className, final ClassLoader classLoader) { // load the class! try { final ClassLoader cl = classLoader == null ? Thread.currentThread().getContextClassLoader() : classLoader; return cl.loadClass(className); } catch (final ClassNotFoundException e) { return null; } } }