public interface CallBackInterface {
public void doSome();
public void executeMethod();
}
public class MethodB {
public double getTime(CallBackInterface callBack) {
long start = System.currentTimeMillis();
callBack.executeMethod();
long end = System.currentTimeMillis();
System.out.println("cost time=" + (end - start));
return end - start;
}
}
public class MethodA {
public static void main(String[] args) {
MethodB b = new MethodB();
// 返回值d只和MethodB有关,和接口中方法的返回值无关
double d = b.getTime(new CallBackInterface() {
public void executeMethod() {
new MethodA().testMethod();
}
public void doSome() {
}
});
}
}