Java Class Load getClass(String name)

Here you can find the source of getClass(String name)

Description

Returns a Java class object for the specified class name.

License

Creative Commons License

Parameter

Parameter Description
name The class name, either fully qualified or just the simple name

Exception

Parameter Description
Exception an exception

Return

The class, if found, otherwise throws exception

Declaration

public static Class<?> getClass(String name) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<String, Class<?>> classes = new HashMap<String, Class<?>>();

    /**/*from  w  ww. jav  a2 s. c  om*/
     * Returns a Java class object for the specified class name.
     * 
     * @param name The class name, either fully qualified or just the simple name
     * @return The class, if found, otherwise throws exception
     * @throws Exception
     */
    public static Class<?> getClass(String name) throws Exception {
        for (String clazz : classes.keySet()) {
            if (clazz.toLowerCase().contains(name.toLowerCase())) {
                return classes.get(clazz);
            }
        }

        throw new Exception(
                "Class "
                        + name
                        + " not found, try including the package name, for instance: net.minecraft.server._version_."
                        + name);
    }
}

Related

  1. getClass(Class clazz)
  2. getClass(String className)
  3. getClass(String className)
  4. getClass(String className)
  5. getClass(String fullClassName)
  6. getClass(String name)
  7. getClass(String upnpDataType)
  8. getClassDescriptor(Class type)
  9. getClasses(Class infoClass)