回调用于指定一个方法的具体行为。下面用实例来解释:
package testcallback; public interface Action { public void performAction(); }
package testcallback; public class ActionImpl implements Action { @Override public void performAction() { // TODO Auto-generated method stub System.out.println("perform action"); } }
package testcallback; public class UseAction { public void useAction(Action action) { action.performAction(); } }
package testcallback; public class TestCallback { public static void main(String[] args) { // TODO Auto-generated method stub Action action = new ActionImpl(); UseAction useAction = new UseAction(); /** * 指定useAction(Action action)中 * 执行ActionImpl的performAction() * 方法 */ useAction.useAction(action); } }
perform action
原文地址:http://blog.csdn.net/l294265421/article/details/46573035