<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 昨夜人生 閱讀(182) 評論(0)  編輯  收藏 所屬分類: 其他

    主站蜘蛛池模板: 精品亚洲成A人无码成A在线观看| 亚洲成av人片在线观看天堂无码| 国产成人精品日本亚洲| 一区二区3区免费视频| 亚洲 另类 无码 在线| 一级黄色片免费观看| 国产精品亚洲mnbav网站| 国产免费内射又粗又爽密桃视频| 久久久久久A亚洲欧洲AV冫| 99re6在线精品免费观看| 国产亚洲精品精华液| 久久免费区一区二区三波多野| 水蜜桃亚洲一二三四在线| 曰批全过程免费视频网址| 亚洲一区二区三区亚瑟| 夜夜嘿视频免费看| 黄色免费在线网址| 亚洲国产精品无码AAA片| 最近中文字幕mv免费高清视频8| 亚洲一区动漫卡通在线播放| 日本免费网站观看| 一个人免费观看日本www视频| 在线播放亚洲第一字幕| 3344免费播放观看视频| 国产成人精品日本亚洲语音| 亚洲欧洲日产国码无码久久99| 精品免费视在线观看| 亚洲色大成网站www久久九| 亚洲AV无码专区日韩| 久久国产精品萌白酱免费| 国产成人精品日本亚洲18图| 亚洲AV无码不卡在线观看下载| 国产真人无码作爱免费视频| 亚洲嫩草影院在线观看| 国产91在线免费| 无码国产精品一区二区免费3p | 午夜不卡久久精品无码免费| 亚洲日韩AV一区二区三区中文| 亚洲日韩在线中文字幕第一页| 永久免费在线观看视频| www.xxxx.com日本免费|