@XQF
2017-02-15T03:46:13.000000Z
字数 653
阅读 1250
java
interface Hehe {void print(String str);}public class Test {public void print(String str, Hehe hehe) {if (hehe != null) {hehe.print(str);}}public static void main(String[] args) {Test t = new Test();t.print("测试", new Hehe() {@Overridepublic void print(String str) {System.out.println(str + "结束");}});}}
interface Hehe {void print(String str);}class Haha implements Hehe {@Overridepublic void print(String str) {System.out.println(str + "结束");}}public class Test {public void print(String str, Hehe hehe) {if (hehe != null) {hehe.print(str);}}public static void main(String[] args) {Test t = new Test();t.print("测试", new Haha());}}
说是这样的回调似乎是实现了C++里面的函数指针的问题。好像是,,。,说的也对。
接口的引用就相当于是函数指针。
