Java???????
???????????? ???????[ 2012/12/5 10:26:55 ] ????????
??????C/C++?У???????????????????????????????????????????????JAVA???????????????????????????interface??????????????????
???????????java????????????????????????????????????????????????????????????????????????????????
public class TestObject {
/**
* ??????????????????????????????????????
*/
public static void testMethod(){
for ( int i= 0 ; i< 100000000 ; i++){
}
}
/**
* ???????????????????????
*/
public void testTime(){
long begin = System.currentTimeMillis(); //??????????
testMethod(); //???????
long end = System.currentTimeMillis(); //??????????
System.out.println("[use time]:" + (end - begin)); //?????????
}
public static void main(String[] args) {
TestObject test=new TestObject();
test.testTime();
}
}
????????????testTime()?????????"//???????"?????????????????????????????????????????????
???????????????????
public interface CallBack {
//??л???????????
void execute();
}
?????????д?????????
public class Tools {
/**
* ????????????????????CallBack????execute????
* @param callBack
*/
public void testTime(CallBack callBack) {
long begin = System.currentTimeMillis(); //??????????
callBack.execute(); ///???л??????
long end = System.currentTimeMillis(); //??????????
System.out.println("[use time]:" + (end - begin)); //?????????
}
public static void main(String[] args) {
Tools tool = new Tools();
tool.testTime(new CallBack(){
//????execute????
public void execute(){
//????????????????????????????????
TestObject.testMethod();
}
});
}
}
????????????testTime()??????callback????execute()??????????????????
????????????ɡ??????Aд????γ???????a????????????л???????????????????ó????????B???a????????????b?е????????????????????a?е????????b?е??????
public class Caller
{
public MyCallInterface mc;
public void setCallfuc(MyCallInterface mc)
{
this.mc= mc;
}
public void call(){
this.mc.method();
}
}
????????????????????????????B???????????д??????????
public interface MyCallInterface
{
public void method();
}
??????????????B???????????????????????????
public class B implements MyCallInterface
{
public void method()
{
System.out.println("???");
}
public static void main(String args[])
{
Caller call = new Caller();
call.setCallfuc(new B());
call.call();
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11