Java Class Load loadClass(final String className)

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

Description

Attempts to create a class from a String.

License

Open Source License

Parameter

Parameter Description
className the name of the class to create.

Exception

Parameter Description
IllegalArgumentException if the className does not exist.

Return

the class. CANNOT be NULL.

Declaration

@SuppressWarnings("unchecked")
public static <T> Class<T> loadClass(final String className) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  w w  w. j a v a 2s . c  om*/
     * Attempts to create a class from a String.
     * @param className the name of the class to create.
     * @return the class.  CANNOT be NULL.
     * @throws IllegalArgumentException if the className does not exist.
     */
    @SuppressWarnings("unchecked")
    public static <T> Class<T> loadClass(final String className) throws IllegalArgumentException {
        try {
            return (Class<T>) Class.forName(className);
        } catch (final ClassNotFoundException e) {
            throw new IllegalArgumentException(className + " class not found.");
        }
    }
}

Related

  1. loadClass(ClassLoader loader, String className)
  2. loadClass(ClassLoader loader, String className, String errorMessage)
  3. loadClass(final ClassLoader cl, final String cname)
  4. loadClass(final ClassLoader classLoader, final String classname)
  5. loadClass(final String className)
  6. loadClass(final String className)
  7. loadClass(final String className)
  8. loadClass(final String className)
  9. loadClass(final String className, final ClassLoader classLoader)