@FunctionalInterface
public interface B {
public void exec(String str);
public default B andThen(B b) {
return str -> {
exec(str);
b.exec(str);
};
}
}
等效于:
@FunctionalInterface
public interface B {
public void exec(String str);
public default B andThen(B b) {
return str -> {
this.exec(str);
b.exec(str);
};
}
}
等效于:
@FunctionalInterface
public interface B {
public void exec(String str);
public default B andThen(B b) {
return str -> {
B.this.exec(str);
b.exec(str);
};
}
}
等效于:
@FunctionalInterface
public interface B {
public void exec(String str);
public default B andThen(B b) {
return new B() {
public void exec(String str) {
// System.out.println(this);
B.this.exec(str);
b.exec(str);
}
};
}
}
不等于:
@FunctionalInterface
public interface B {
public void exec(String str);
public default B andThen(B b) {
return new B() {
public void exec(String str) {
// System.out.println(this);
this.exec(str);// (或exec(str))此处的this指的是自己,会发生死循环
b.exec(str);
}
};
}
}