Java?е???????
???????????? ???????[ 2015/10/9 13:24:16 ] ??????????????????? ???????
????????????????
????packagecallbackexample;
????publicinterfaceICallBack{
????publicvoidpostExec();//???????????
????}
??????????????
????packagecallbackexample;
????publicclassFooBar{//????????
????privateICallBackcallBack;
????publicvoidsetCallBack(ICallBackcallBack)
????{this.callBack=callBack;doSth();}
????publicvoiddoSth()
????{callBack.postExec();}}
?????????????????????棬???????????
????packagecallbackexample;
????publicclassTest{
????publicstaticvoidmain(String[]args)
????{FooBarfoo=newFooBar();
????foo.setCallBack(newICallBack(){
????publicvoidpostExec()
????{System.out.println("??Test?????????????Test??????????????FooBar???????");}});}}
????????????У?
????1.?????????????FooBar
????2.???????????ICallBack(??test?????main?????????????????????)
????3.FooBar???????????ICallBack???????????setCallBack(ICallBacko)
????4.???????????????FooBar??setCallBack??????????????????
????5.FooBar???????????????????????????????????ICallBack????е????
?????????????????????“??????”?????????????????????java????????????????????????????
???????????????“???”??????Щ??????????????????÷?????κ??????“???”?????????????“???????”
?????????????????????“java???”??“??????”????ù????С?
?????????н?????ICallBack?????з??????postExec()
????????Myclass?????y??????????????postExec()??????????????????????FooBar???и?????setCallBack(ICallBackcallBack)??????setCallBack??????????callBack??postExec()??????
??????????????????????Myclass?????myClass?????????????????setCallBack(ICallBackcallBack)?????У??????setCallBack(ICallBackcallBack)?????????myClass??postExec()??????
????Java?????????????????????????Java??e??????????????????????????(callback)?????????????????Я???Щ???????Щ???????????????????????ó???????
?????????????????????????????????????????????????????????????????????Java??С?????????????????????а??????
???????????????????????????????????????????????????????
?????????????????
//innerclasses/Callbacks.java
//Usinginnerclassesforcallbacks
packageinnerclasses
interfaceIncrementable{
voidincrement();
}
//Verysimpletojustimplementtheinterface
classCallee1implementsIncrementable{
privateinti=0;
publicvoidincrement(){
i++;
System.out.println(i);
}
}
classMyIncrement{
publicvoidincrement(){System.out.println("Otheroperation");}
staticvoidf(MyIncrementmi){mi.increment();}
}
//Ifyourclassmustimplementincrement()in
//someotherway??youmustuseaninnerclass:
classCallee2extendsMyIncrement{
privateinti=0;
publicvoidincrement(){
super.increment();
i++;
System.out.println(i);
}
privateclassClosureimplementsIncrementable{
publicvoidincrement(){
//Specifyouter-classmethod??otherwise
//you'dgetaninfiniterecursion
Callee2.this.increment();
}
}
IncrementablegetCallbackReference(){
returnnewClosure();
}
}
classCaller{
privateIncrementablecallbackReference;
Caller(Incrementablecbh){callbackReference=cbh;}
voidgo(){callbackReference.increment();}
}
publicclassCallbacks{
publicstaticvoidmain(String[]args){
Callee1c1=newCallee1();
Callee2c2=newCallee2();
MyIncrement.f(c2);
Callercaller1=newCaller(c1);
Callercaller2=newCaller(c2.getCallbackReference());
caller1.go();
caller1.go();
caller2.go();
caller2.go();
}
}
?????????
????Otheroperation
????1
????1
????2
????Otheroperation
????2
????Otheroperation
????3
?????????????????????Χ????????????????????????????????????????Callee1????????????Callee2?????MyIncrement?????????????????????increment()????????????Incrementable?????????increment()?????????????
???????????Callee2?????MyIncrement?????????Incrementable???????????increment()?????????????????????????????Incrementable????????????????????????????????????Χ????????????????????????Χ??????
?????????Callee2?г???getCallbackReference()???????????????private??????????????????κ??????interfaceIncrementable???????????????????????interface?????????????????????????????
?????????Closure?????Incrementable???????????Callee2??“????”(hook)——???????????????????????????Incrementable???????????????increment()????????????????????(????????????????????????????)??
????Caller?????????????Incrementable?????????????(?????????????????????????)??????????????????(Caller?????????????????Callee??
????????????????????????——??????????????????????????????????
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
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????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????