Here you can find the source of loadClass(Class context, String... names)
Parameter | Description |
---|---|
context | The class to use as the context (uses this class's classloader). |
names | One or more fully qualified class names. |
@SuppressWarnings("rawtypes") public static Class<?> loadClass(Class context, String... names)
//package com.java2s; /**/*w ww. j ava2s .c o m*/ * Copyright (C) 2012 - 2013 Eric Van Dewoestine * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Attempt to load a class for one ore more supplied class names, returning * the first one found. Useful for handling cross eclipse version * compatibility. * * @param context The class to use as the context (uses this class's * classloader). * @param names One or more fully qualified class names. * @return A Class for the first class found or null if none found. */ @SuppressWarnings("rawtypes") public static Class<?> loadClass(Class context, String... names) { for (String name : names) { try { Class<?> clazz = Class.forName(name, true, context.getClassLoader()); return clazz; } catch (ClassNotFoundException cnfe) { // ignore, try the next name. } } return null; } }