Java Class Load loadClass(String className)

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

Description

Loads a class with the given name.

License

Apache License

Parameter

Parameter Description
className a parameter

Exception

Parameter Description
ClassNotFoundException If not found

Return

The class object

Declaration

public static <T> Class<T> loadClass(String className) throws ClassNotFoundException 

Method Source Code

//package com.java2s;
/**/*from  w  w  w .  ja  v  a  2 s . c  o  m*/
 * Copyright (C) 2000-2010 Atomikos <info@atomikos.com>
 *
 * This code ("Atomikos TransactionsEssentials"), by itself,
 * is being distributed under the
 * Apache License, Version 2.0 ("License"), a copy of which may be found at
 * http://www.atomikos.com/licenses/apache-license-2.0.txt .
 * You may not use this file except in compliance with the License.
 *
 * While the License grants certain patent license rights,
 * those patent license rights only extend to the use of
 * Atomikos TransactionsEssentials by itself.
 *
 * This code (Atomikos TransactionsEssentials) contains certain interfaces
 * in package (namespace) com.atomikos.icatch
 * (including com.atomikos.icatch.Participant) which, if implemented, may
 * infringe one or more patents held by Atomikos.
 * It should be appreciated that you may NOT implement such interfaces;
 * licensing to implement these interfaces must be obtained separately from Atomikos.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

public class Main {
    /**
     * Loads a class with the given name.
     * 
     * @param className
     * @return The class object
     * @throws ClassNotFoundException
     *             If not found
     */
    public static <T> Class<T> loadClass(String className) throws ClassNotFoundException {
        Class<T> clazz = null;
        try {
            clazz = (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(className);
        } catch (ClassNotFoundException nf) {
            clazz = (Class<T>) Class.forName(className);
        }
        return clazz;
    }
}

Related

  1. loadClass(String className)
  2. loadClass(String className)
  3. loadClass(String className)
  4. loadClass(String className)
  5. loadClass(String className)
  6. loadClass(String className)
  7. loadClass(String className)
  8. loadClass(String className)
  9. loadClass(String className)