标签:uri cto cat ack name catch etc ace target
public class ReflectTest { public static void main(String[] args) { try { Class obj = ReflectTest.class.getClassLoader().loadClass("com.test.GetPackageName"); GetPackageName name = (GetPackageName) obj.getConstructor(String.class,String.class).newInstance("hello","xx"); System.out.println(name.toString()); } catch (ClassNotFoundException 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(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public GetPackageName() { System.out.println(" 构造函数"); } public GetPackageName(String str) { System.out.println(str); } public GetPackageName(String str,String str2) { System.out.println("c2"+str+str2); }
标签:uri cto cat ack name catch etc ace target
原文地址:https://www.cnblogs.com/kakaisgood/p/10214557.html