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

    主站蜘蛛池模板: 毛片网站免费在线观看| 日本亚洲视频在线| 91精品全国免费观看青青| 亚洲第一福利网站| 午夜dj免费在线观看| a级毛片在线免费观看| 亚洲人成电影青青在线播放| 免费欧洲毛片A级视频无风险| 亚洲国产一级在线观看 | 国产a视频精品免费观看| 亚洲一区二区三区高清视频| 亚洲AV无码一区二区三区在线观看| 亚洲日韩一区二区一无码| 久久精品国产精品亚洲| 国产a视频精品免费观看| 一级白嫩美女毛片免费| 亚洲中字慕日产2021| 精品国产亚洲男女在线线电影| 一级毛片完整版免费播放一区| 国产精品黄页在线播放免费| 嫩草影院在线播放www免费观看| 亚洲人精品午夜射精日韩| 国产乱子精品免费视观看片| 一级午夜免费视频| 在线综合亚洲欧洲综合网站| 亚洲bt加勒比一区二区| 亚洲欧洲自拍拍偷精品 美利坚| 免费无码国产V片在线观看| 亚洲av永久无码嘿嘿嘿| 亚洲综合国产一区二区三区| 日本黄色免费观看| 麻豆最新国产剧情AV原创免费 | 美女内射无套日韩免费播放| 亚洲a∨国产av综合av下载| 亚洲综合亚洲国产尤物| 国产亚洲A∨片在线观看| 午夜亚洲国产成人不卡在线| 免费中文熟妇在线影片 | 亚洲AV无码国产一区二区三区| 国产91久久久久久久免费| 国产桃色在线成免费视频|