还是自己写的看的容易明白
import java.util.*;
public class Main {
public static void main(String[] args) {
Student st=new Student();
st.doTask(new CallBack(){
@Override
public void taskResult(float percent) {
if(percent<1f){
System.out.println("未完成任务");
}
else{
System.out.println("完成任务");
}
}
});
}
}
class Student{
private float percent;
public Student(){
}
public void doTask(final CallBack callBack){
new Thread(new Runnable(){
@Override
public void run() {
for(int i=1;i<=10;i++){
try {
Thread.sleep(100);
percent=(float)i/10;
System.out.println("完成率:"+percent);
} catch (InterruptedException e) {}
}
callBack.taskResult(percent);
}
}).start();
}
}
interface CallBack{
void taskResult(float percent);
}