精彩的人生

          好好工作,好好生活

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            147 Posts :: 0 Stories :: 250 Comments :: 0 Trackbacks
          今天在搜尋tree的實(shí)現(xiàn),找到了這段代碼,覺(jué)得很有用但是還沒(méi)想到怎么用,先保存在這里


          一般用匿名內(nèi)部類實(shí)現(xiàn)callback


          public interface YourInterface {

            public void interfaceMethod();

          }


          public class YourClass{

            public void classMethod(YourInterface yInterface)
            {
                  ......
                  yInterface.interfaceMethod();
                  ......
              }
           
            public static void main(String[] args)
            {
                YourClass yClass = new YourClass();

                yClass.classMethod(new YourInterface()
                {
                    public void interfaceMethod()
                    {
                        //do sth
                        System.out.print("hello world.");
                        .......   
                    }
                });
          }

          posted on 2008-09-16 14:14 hopeshared 閱讀(1537) 評(píng)論(3)  編輯  收藏 所屬分類: Java

          Feedback

          # re: 一段關(guān)于callback的代碼[未登錄](méi) 2008-09-24 11:18 eclipser
          回調(diào)方法比模板方法更經(jīng)常使用,呵呵。

          比如給一個(gè)按鈕添加一個(gè)SelectionListener,方式不就是你說(shuō)的嗎?

          注冊(cè)listener時(shí),指定單擊時(shí)的回調(diào)方法,然后實(shí)際單擊這個(gè)按鈕時(shí),就回調(diào)你注冊(cè)的這個(gè)Listener的實(shí)現(xiàn),

          你對(duì)Eclipse那么熟悉,我說(shuō)的對(duì)嗎?  回復(fù)  更多評(píng)論
            

          # re: 一段關(guān)于callback的代碼 2009-02-27 22:15 www.iq250.com
          【智商250】http://www.iq250.com
          【生活大家壇】http://bbs.iq250.com   回復(fù)  更多評(píng)論
            

          # re: 一段關(guān)于callback的代碼 2009-11-19 21:57 柳凈園
          這個(gè)代碼有什么用?  回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 酒泉市| 贵港市| 咸阳市| 青海省| 屯昌县| 临夏县| 伊宁县| 财经| 乌兰浩特市| 合山市| 茂名市| 雷山县| 德州市| 白玉县| 旌德县| 肇州县| 察隅县| 璧山县| 鸡西市| 沙湾县| 诸暨市| 格尔木市| 彭泽县| 隆子县| 武川县| 南川市| 天水市| 遂昌县| 京山县| 广安市| 囊谦县| 平谷区| 庄河市| 台州市| 弋阳县| 星子县| 宁德市| 辽源市| 全椒县| 屏南县| 海安县|