java 接口式自定义回调函数

  1. 定义接口
package com.zjxnjz.mall.admin.test;

	public interface CallBack {
		
		void handler(String message);
	
	}
  1. 测试
package com.zjxnjz.mall.admin.test;
	
	public class TestCallBack {
		
		public static void setHello(CallBack callback) {
			int count=0;
			while(count<=100) {
				count++;
			}
			callback.handler("执行结束了");
		}
		
		
		public static void main(String[] args) {
			setHello(new CallBack() {
				@Override
				public void handler(String message) {
					System.out.println(message);
				}});
		}
	
	}

你可能感兴趣的:(java 接口式自定义回调函数)