Java Class Load loadClassSafe(final String klassName)

Here you can find the source of loadClassSafe(final String klassName)

Description

Loads a class with given klassName.

License

Open Source License

Declaration

public static Class<?> loadClassSafe(final String klassName) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from ww w . j  av  a 2s  .  c o  m
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/

public class Main {
    /** Loads a class with given klassName. 
     * Returns null if the class could not be loaded. */
    public static Class<?> loadClassSafe(final String klassName) {
        try {
            return Class.forName(klassName);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }
}

Related

  1. loadClassFromClassLoader( String fillyQualifiedClassName)
  2. loadClassFromContextClassLoader(String theClassName)
  3. loadClassOrNull(String className)
  4. loadClassOrReturnNull(ClassLoader loader, String className)
  5. loadClassReflectively(ClassLoader classLoader, String fullyQualifiedClassName)
  6. loadClassSilently(ClassLoader cl, String name)
  7. loadClassUsingClass(Class clazz, String name)
  8. loadClassViaContext(String fqcn)
  9. loadClassWithTCCL(String name)