Java Class Load loadClass(String className, Class context, boolean checkParent)

Here you can find the source of loadClass(String className, Class context, boolean checkParent)

Description

Loads a class from the classloader; If not found, the classloader of the context class specified will be used.

License

Apache License

Declaration

static Class<?> loadClass(String className, Class<?> context, boolean checkParent) 

Method Source Code

//package com.java2s;
//Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**//from  ww w .j  a va2s  .  c  om
     * Loads a class from the classloader; If not found, the classloader of the {@code context} class specified will be
     * used. If the flag {@code checkParent} is true, the classloader's parent is included in the lookup.
     */
    static Class<?> loadClass(String className, Class<?> context, boolean checkParent) {
        Class<?> clazz = null;
        try {
            clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
        } catch (ClassNotFoundException e) {
            if (context != null) {
                ClassLoader loader = context.getClassLoader();
                while (loader != null) {
                    try {
                        clazz = loader.loadClass(className);
                        return clazz;
                    } catch (ClassNotFoundException e1) {
                        loader = checkParent ? loader.getParent() : null;
                    }
                }
            }
        }
        return clazz;
    }
}

Related

  1. loadClass(String className, boolean isInitialized)
  2. loadClass(String className, Class callingClass)
  3. loadClass(String classname, Class clazz)
  4. loadClass(String classname, Class clazz)
  5. loadClass(String classname, Class clazz)
  6. loadClass(String className, Class ofType)
  7. loadClass(String className, Class targetType, ClassLoader cl)
  8. loadClass(String className, Class type)
  9. loadClass(String className, ClassLoader cl)