Java反射

            ClassLoader loader= Thread.currentThread().getContextClassLoader();
            Class clz = loader.loadClass("com.easeye.test.Student");
            Constructor[] con= clz.getConstructors();
            //Student stu = (Student) con[0].newInstance("ST001","陈文光",30);
            // stu.ShowInfo();
            
            Object stu =  con[0].newInstance("ST001","陈文光",30);
            Method method1 =clz.getDeclaredMethod("ShowInfo");
            method1.invoke(stu);
            
            Method method2 = clz.getDeclaredMethod("Say", java.lang.String.class,java.lang.Integer.class);
            method2.invoke(stu, "大家好",1);

posted @ 2015-10-14 22:39  常平  阅读(120)  评论(0编辑  收藏  举报