(1)super引用父类方法
public class Human extends Man {
@Override
public void sayHello() {
System.out.println("我是Human");
}
public void method(Greentable g){
g.green();
}
public void show(){
//使用匿名内部类实现
method(new Greentable() {
@Override
public void green() {
Man man = new Man();
man.sayHello();
}
});
//使用Lambda表达式优化
method(()->{
super.sayHello();
});
//使用方法引用优化
method(super::sayHello);
}
public static void main(String[] args) {
Human human = new Human();
human.show();
}
}
(2)父类
public class Man {
public void sayHello(){
System.out.println("我是Man");
}
}
(3)函数式接口
@FunctionalInterface
public interface Greentable {
void green();
}