📄 objectfactory.java
字号:
package net.sf.dz.util;/** * A simple object factory. * * @author Copyright © <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2001 * @version $Id: ObjectFactory.java,v 1.2 2004/06/28 20:35:49 vtt Exp $ */public class ObjectFactory { /** * Try to instantiate the object and check the class it has to be * assignable to. * * <p> * * Besides the documented exception, this method will throw the * exceptions related to <code>Class.forName()</code> and * <code>Class.newInstance()</code>. * * @param className Class name to instantiate. * * @param template Class the resulting object has to be assignable to. * * @exception IllegalArgumentException if the result is not assignable * to the template class. */ public static Object instantiate(String className, Class template) throws Throwable { if ( className == null || "".equals(className)) { throw new IllegalArgumentException("Empty class name specified for " + template.getName()); } Class objectClass = Class.forName(className); Object theObject = objectClass.newInstance(); if ( template.isInstance(theObject) ) { return theObject; } throw new IllegalArgumentException("Expected " + template.getName() + ", got " + theObject.getClass().getName()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -