Here you can find the source of loadClass(String className, Class
public static <T> Class<T> loadClass(String className, Class<T> targetType, ClassLoader cl) throws Exception
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * //from ww w . ja v a 2 s.com * http://www.apache.org/licenses/LICENSE-2.0 *******************************************************************************/ public class Main { public static <T> Class<T> loadClass(String className, Class<T> targetType, ClassLoader cl) throws Exception { return loadClass(className, targetType, false, cl); } public static <T> Class<T> loadClass(String className, Class<T> targetType, boolean ignoreMissingClass, ClassLoader cl) throws Exception { String targetTypeName; if (targetType != null) { targetTypeName = targetType.getName(); } else { targetTypeName = "(unspecified assignment type)"; } Class clazz; try { clazz = Class.forName(className, true, cl); } catch (NoClassDefFoundError err) { throw new Exception(err); //throw new Exception(SystemErrorTypes.SVC_FACTORY_INST_NOT_FOUND, // new Object[] {targetTypeName, className}, err); } catch (ClassNotFoundException e) { if (ignoreMissingClass) { return null; } throw new Exception(e); // throw new ServiceException(SystemErrorTypes.SVC_FACTORY_INST_NOT_FOUND, // new Object[] {targetTypeName, className}, e); } if (targetType != null && !targetType.isAssignableFrom(clazz)) { throw new Exception( "instance cannot cast - targetTypeName: " + targetTypeName + ", className: " + className); // throw new ServiceException(SystemErrorTypes.SVC_FACTORY_INST_CANNOT_CAST, // new Object[] {targetTypeName, className}); } @SuppressWarnings("unchecked") Class<T> result = clazz; return result; } }