Java Class Load classForName(String cname)

Here you can find the source of classForName(String cname)

Description

Returns the class with the given name, or null if it's not on the path.

License

LGPL

Parameter

Parameter Description
cname class name

Return

class or null

Declaration

public static Class classForName(String cname) 

Method Source Code

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

public class Main {
    /**//w  ww  . jav  a2 s . co  m
     * Returns the class with the given name, or null if it's not on the
     * path.
     *
     * @param   cname  class name
     * @return  class or null
     */
    public static Class classForName(String cname) {

        // Hmm - not sure now why I wanted to make sure I got this classloader.
        // I wonder if there is a good reason??
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try {
            return Class.forName(cname, true, loader);
        } catch (ClassNotFoundException e) {
            return null;
        }
    }
}

Related

  1. classForName(String className)
  2. classForName(String className, Class caller)
  3. classForName(String className, Class superClass)
  4. classForName(String className, ClassLoader classLoader)
  5. classForName(String clazzName, ClassLoader classLoader)
  6. classForName(String columnType)
  7. classForName(String listener)
  8. classForName(String name)
  9. classForName(String name)