Java Class forName forNames(String[] classNames)

Here you can find the source of forNames(String[] classNames)

Description

Returns the Class object array associated with the class or interface with the given string name array.

License

Open Source License

Parameter

Parameter Description
classNames the fully qualified names of the desired classes.

Exception

Parameter Description
ClassNotFoundException an exception

Return

the Class object array for the classes with the specified names.

Declaration

public static Class[] forNames(String[] classNames) throws ClassNotFoundException 

Method Source Code

//package com.java2s;
/* //  w  w  w. ja  v a  2 s  .  c o m
 * Copyright(c) 2005 Center for E-Commerce Infrastructure Development, The
 * University of Hong Kong (HKU). All Rights Reserved.
 *
 * This software is licensed under the GNU GENERAL PUBLIC LICENSE Version 2.0 [1]
 * 
 * [1] http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
 */

public class Main {
    /**
     * Returns the Class object array associated with the class or interface
     * with the given string name array.
     * 
     * @param classNames the fully qualified names of the desired classes.
     * @return the Class object array for the classes with the specified names.
     * @throws ClassNotFoundException
     */
    public static Class[] forNames(String[] classNames) throws ClassNotFoundException {
        int size = (classNames == null ? 0 : classNames.length);
        Class[] classes = new Class[size];
        for (int i = 0; i < classes.length; i++) {
            classes[i] = Class.forName(classNames[i]);
        }
        return classes;
    }
}

Related

  1. forName(String type, Class cast)
  2. forName(String[] classNames)
  3. forNameElseNull(final String fullName)
  4. forNameNoException(String className)
  5. forNameOrNull(String className)