精彩的人生

好好工作,好好生活

BlogJava 首页 新随笔 联系 聚合 管理
  147 Posts :: 0 Stories :: 250 Comments :: 0 Trackbacks

2008年9月16日 #

今天在搜寻tree的实现,找到了这段代码,觉得很有用但是还没想到怎么用,先保存在这里


一般用匿名内部类实现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 阅读(1516) | 评论 (3)编辑 收藏