少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          package com.abin.lee.reflect;

          import java.lang.reflect.Method;

          public class InvokeTester {
           public int add(int param1,int param2){
            return param1+param2;
           }
           public String echo(String message){
            return "hello"+message;
           }
           public static void main(String[] args) {
            try {
             Class<?> classType=InvokeTester.class;
             Object invokeTester=classType.newInstance();
             System.out.println(invokeTester instanceof InvokeTester);
             Method addMethod=classType.getMethod("add", new Class[]{int.class,int.class});
             Object result=addMethod.invoke(invokeTester, new Object[]{1,2});
             System.out.println((Integer)result);
             
             System.out.println("----------");
             Method echoMethod=classType.getMethod("echo", new Class[]{String.class});
             Object result2=echoMethod.invoke(invokeTester, new Object[]{"abin"});
             System.out.println(result2);
            } catch (Exception e) {
             e.printStackTrace();
             System.out.println(e.getMessage());
            }
           }
          }

          posted on 2012-04-14 02:08 abin 閱讀(569) 評論(0)  編輯  收藏 所屬分類: Java反射機制

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 亳州市| 新乐市| 江华| 南部县| 康马县| 神木县| 长沙县| 黄骅市| 金秀| 龙海市| 定日县| 桐城市| 开封市| 无极县| 务川| 玉田县| 乐东| 读书| 灵石县| 台南市| 江达县| 盐源县| 西宁市| 荥经县| 大渡口区| 郓城县| 德州市| 无棣县| 乌鲁木齐县| 六枝特区| 同仁县| 海门市| 壤塘县| 东乌珠穆沁旗| 阳高县| 浠水县| 绥德县| 偏关县| 连平县| 化德县| 乐昌市|