Get Class from class name

ReturnMethodSummary
static Class<?>forName(String className)Returns the Class object associated with the class or interface with the given string name.
static Class<?>forName(String name, boolean initialize, ClassLoader loader)Returns the Class object associated with the class or interface with the given string name, using the given class loader.

Use Class.forName to create Class from a String


public class Main {

  public static void main(String[] args) {

    try {
      Class c = Class.forName("java.lang.String");
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.