`
vortexchoo
  • 浏览: 64599 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

java中的回调函数

    博客分类:
  • java
 
阅读更多

用惯了ajax,喜欢上了回调函数。所以写了个小例子实现了下java 中的回调

 

public interface CallBackInterface {
	
	public void doCallBack(String str);
	
}



public class CallBackMethod {
	
	public void doCallBack(String str,CallBackInterface call){
		//加工传入参数并得到最终结果res
		String res = str + "callBack";
		//将res传入接口
		call.doCallBack(res);
	}
	
}




public class Test {
	
	public static void main(String[] args) {
		new CallBackMethod().doCallBack("show ", new CallBackInterface(){
			@Override
			public void doCallBack(String str) {
				// TODO Auto-generated method stub
				System.out.println(str);
			}
			
		});
	}
}

 通过回调函数,我们拿到了加工后的值。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics