标签:package object public return import
1、调用实现类
package com.commons.util; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @SuppressWarnings("all") public class ReflectionUtil { public static Object getBean(String className) { try { Class cls = Class.forName(className); Constructor cons = cls.getConstructor(); Object object = cons.newInstance(new String[]{}); return object; } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }
标签:package object public return import
原文地址:http://microe.blog.51cto.com/3332651/1685171