码迷,mamicode.com
首页 > 其他好文 > 详细

反射实例测试代码

时间:2019-01-03 16:34:59      阅读:176      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!