Quantcast
Channel: BlogJava-精彩的人生
Viewing all articles
Browse latest Browse all 5

一段关于callback的代码

$
0
0
今天在搜寻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.");
              .......   
          }
      });
}



hopeshared 2008-09-16 14:14 发表评论

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images