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