Java Class Load loadClassOrNull(String className)

Here you can find the source of loadClassOrNull(String className)

Description

load Class Or Null

License

Apache License

Declaration

public static Class<?> loadClassOrNull(String className) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    private static ClassLoader classLoader;

    public static Class<?> loadClassOrNull(String className) {
        ClassLoader loader = getClassLoaderForResolving();
        try {// ww  w .j  a  v a 2s.c  o  m
            return loader.loadClass(className);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }

    public static ClassLoader getClassLoaderForResolving() {
        ClassLoader cl = classLoader;
        if (cl == null) {
            // TODO:possibly want one which doesn't cache the classes?
            cl = Thread.currentThread().getContextClassLoader();
        }
        return cl;
    }
}

Related

  1. loadClassByName(final String className, final ClassLoader loader)
  2. loadClassByName(String className)
  3. loadClassElseThrow(final String enumType)
  4. loadClassFromClassLoader( String fillyQualifiedClassName)
  5. loadClassFromContextClassLoader(String theClassName)
  6. loadClassOrReturnNull(ClassLoader loader, String className)
  7. loadClassReflectively(ClassLoader classLoader, String fullyQualifiedClassName)
  8. loadClassSafe(final String klassName)
  9. loadClassSilently(ClassLoader cl, String name)