<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    自寫自看

    利用方法名稱執行方法行為的源代碼

    public class TestReflectCommand {


    public static void main(String[] args){

    CommandLoader cl=new DefaultCommandLoader(new DefaultShowCommand());
    cl.excute("executeShowList",null);
    }
    }

    public interface CommandLoader {

    void excute(String commandName,Object[] argument);
    }


    public class DefaultCommandLoader implements CommandLoader {


    private ShowCommand showCommand;

    private HashMap subCommandMap=new HashMap();

    public DefaultCommandLoader(ShowCommand showCommand){
    this.showCommand=showCommand;
    init();
    }


    private void init() {

    Method[] allMethod=this.showCommand.getClass().getMethods();
    for(int i=0;i<allMethod.length;i++){
    Method m=allMethod;
    if(m.getName().startsWith("execute")){
    subCommandMap.put(m.getName(), m);
    }
    }
    }


    public void excute(String commandName, Object[] argument) {

    Method m=(Method) this.subCommandMap.get(commandName);

    if(m==null){
    throw new NullPointerException("not found command");
    }
    try{
    m.invoke(this.showCommand,argument);
    }
    catch(Exception e){
    throw new RuntimeException("Load command["+m.getName()+"error");
    }
    }
    }

    public interface ShowCommand {


    public void executeShowList();

    public void excuteShowString();

    public void executeShowInteger();

    public void executeShowLong();
    }

    public class DefaultShowCommand implements ShowCommand {

    public void excuteShowString() {
    System.out.println(String.class.getName());
    }

    public void executeShowInteger() {
    System.out.println(Integer.class.getName());
    }

    public void executeShowList() {
    System.out.println(List.class.getName());
    }

    public void executeShowLong() {
    System.out.println(Long.class.getName());
    }

    }

    posted on 2008-02-25 11:48 昨夜人生 閱讀(181) 評論(0)  編輯  收藏 所屬分類: 其他

    主站蜘蛛池模板: 久久成人免费大片| 国产成人亚洲合集青青草原精品 | 91大神亚洲影视在线| 国产亚洲精AA在线观看SEE| 亚洲AV无码国产丝袜在线观看| 亚洲小视频在线播放| 未满十八私人高清免费影院| 一级特黄录像免费播放肥| 6080午夜一级毛片免费看| 国产成人在线免费观看| 亚洲乱码中文字幕综合| 亚洲一区综合在线播放| 亚洲国产成人久久精品软件| 日本在线免费观看| 亚洲视频一区二区三区| 啦啦啦中文在线观看电视剧免费版| 亚洲成AⅤ人影院在线观看| 亚洲ts人妖网站| 你好老叔电影观看免费| 天天拍拍天天爽免费视频| 色婷婷六月亚洲婷婷丁香| 五月亭亭免费高清在线| 国产亚洲3p无码一区二区| 成全视频高清免费观看电视剧 | 亚洲一区无码精品色| 亚洲娇小性xxxx| 国产免费牲交视频| 亚洲精品无码成人片久久不卡| 特级精品毛片免费观看| 美腿丝袜亚洲综合| 四虎国产精品成人免费久久| 国产亚洲色婷婷久久99精品| 在线看片v免费观看视频777| 亚洲福利在线视频| 国产永久免费高清在线| 亚洲二区在线视频| 妻子5免费完整高清电视| 亚洲精品人成电影网| 久久久久国产精品免费网站| 亚洲jizzjizz在线播放久| 亚洲国产精品无码久久九九|