<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)  編輯  收藏 所屬分類: 其他

    主站蜘蛛池模板: 情人伊人久久综合亚洲| 国产亚洲色婷婷久久99精品91| 久久精品九九亚洲精品天堂| 一级午夜a毛片免费视频| 亚洲 无码 在线 专区| 最近免费mv在线观看动漫| 中文字幕精品亚洲无线码一区应用| 思思久久99热免费精品6| 亚洲天堂免费在线视频| caoporm碰最新免费公开视频| 在线a亚洲v天堂网2019无码| 国产性生大片免费观看性| 久久亚洲精品AB无码播放| 成人免费大片免费观看网站| 亚洲欧美日韩综合俺去了| www国产亚洲精品久久久| caoporn成人免费公开| 在线电影你懂的亚洲| 好男人视频在线观看免费看片| 亚洲av成本人无码网站| 精品国产香蕉伊思人在线在线亚洲一区二区 | 91亚洲va在线天线va天堂va国产 | 一个人看www免费高清字幕| 亚洲午夜久久久久妓女影院| 最近2019年免费中文字幕高清| 亚洲国产成a人v在线| 成人免费视频国产| 91视频免费观看| 亚洲三级在线免费观看| 国产一级淫片免费播放电影| 久久一区二区免费播放| 亚洲熟妇av一区二区三区下载| 亚洲性日韩精品一区二区三区 | 久久乐国产精品亚洲综合| 日本免费久久久久久久网站| 亚洲人成在线播放| 亚洲国产精品成人一区| 少妇无码一区二区三区免费| 在线亚洲高清揄拍自拍一品区| 亚洲欧洲日本在线| 免费国产作爱视频网站|