精彩的人生

          好好工作,好好生活

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            147 Posts :: 0 Stories :: 250 Comments :: 0 Trackbacks

          2008年9月16日 #

          今天在搜尋tree的實(shí)現(xiàn),找到了這段代碼,覺(jué)得很有用但是還沒(méi)想到怎么用,先保存在這里


          一般用匿名內(nèi)部類(lè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 @ 2008-09-16 14:14 hopeshared 閱讀(1540) | 評(píng)論 (3)編輯 收藏

          主站蜘蛛池模板: 晋州市| 竹北市| 太谷县| 洪湖市| 安图县| 吉林市| 樟树市| 巴中市| 长白| 嫩江县| 芜湖市| 宜都市| 富源县| 英德市| 麻江县| 沙坪坝区| 宽甸| 玛曲县| 习水县| 鲁山县| 高碑店市| 白朗县| 盱眙县| 吕梁市| 白河县| 长海县| 青海省| 公主岭市| 察隅县| 集安市| 广东省| 沿河| 固镇县| 石首市| 灵川县| 林周县| 固安县| 乌兰察布市| 牡丹江市| 叙永县| 兴义市|