java钩子函数
也不知道我理解的对不对,欢迎大家讨论!
自己写了个钩子函数,我理解的钩子函数:
public interface Transactioner {
String wedontknow() ;</br></br>
}
public abstract class GouZi {
<span style="color:#000080;font-weight:bold;">public abstract void </span><span style="background-color:#e4e4ff;">gouzi</span>(Transactioner t);</br></br>
}
public class Test extends GouZi{
public static void main(String []s){
Test t = new Test();
t.gouzi(new Transactioner() {
@Override
public String wedontknow() {
return "this is from Transactioner---wedontknow";
}
});
}
@Override
public void gouzi(Transactioner t) {
System.out.println("This is from gouzi function");
System.out.print(t.wedontknow());
}
}
=============== 运行结果:
This is from gouzi function
this is from Transactioner---wedontknow