package object01;
interface Eatable {
void taste();
}
interface Flyable {
void fly(String weather);
}
interface Addable {
double add(int a, double b);
}
public class Lambda01 {
public void eat(Eatable shiwu) {
System.out.printf("这个%s真美味!\n", shiwu);
shiwu.taste();
}
public void fly(Flyable weather) {
System.out.println("我正在飞行:" + weather);
weather.fly("太阳每天都在微笑!");
}
private double add(Addable sum) {
System.out.printf("a+b的和为:" + sum.add(5, 3));
return sum.add(5, 3.16);
}
public static void main(String[] args) {
Lambda01 l1 = new Lambda01();
l1.eat(new Eatable() {
@Override
public void taste() {
System.out.println("haochide!");
}
});
l1.fly(new Flyable() {
@Override
public void fly(String weather) {
System.out.println("今天的天气是!" + weather);
System.out.println("直升机飞得很平稳!");
}
});
System.out.println(l1.add(new Addable() {
@Override
public double add(int a, double b) {
return a + b;
}
}));
}
}