public class anonymityInnerclass02 {
public static void main(String[] args) {
father f = ()->{
System.out.println("hello");
};
f.hello();
//当方法体简单只有一行代码的时候 可以省略花括号
f = ()-> System.out.println("当方法体简单只有一行代码的时候 可以省略花括号");
f.hello();
//有一个参数的接口
mother m = (int a)->System.out.println(a);//这里的a是一个形参 不是实参 可以省略int
m.hello(520);
m=a-> System.out.println(a); //一个参数括号也可以省略
m.hello(250);
//两个参数的接口
son s=(number,name)-> System.out.println(name+">>>"+number);
s.hello(18,"任学");//对应顺序
//带返回值
daughter d = (a,b)-> a+b;
System.out.println(d.hello(10, 20));
}
}
interface father {
void hello();
}
interface mother{
void hello(int i);
}
interface son{
void hello(int i ,String name);
}
interface daughter{
int hello(int a,int b);
}