/**
* 方法重载对lambda表达式的影响
*/
public class App4 {
interface Param1 {
void outInfo(String info);
}
interface Param2 {
void outInfo(String info);
}
interface Param3 {
void outInfo(String info, int index);
}
interface Param4 {
void outInfo(String info, int index);
}
public void lambdaMethod_1(Param1 param) {
param.outInfo("hello param1 imooc");
}
public void lambdaMethod_1(Param2 param) {
param.outInfo("hello param1 imooc");
}
public void lambdaMethod_2(Param1 param, int index) {
param.outInfo("hello param1 imooc---" + index);
}
public void lambdaMethod_2(Param2 param, int index) {
param.outInfo("hello param1 imooc---" + index);
}
public void lambdaMethod_3(Param3 param, int index) {
param.outInfo("hello Param3 imooc", index);
}
public void lambdaMethod_3(Param4 param, int index) {
param.outInfo("hello param4 imooc", index);
}
public static void main(String[] args) {
App4 app = new App4();
app.lambdaMethod_1(new Param1() {
@Override
public void outInfo(String info) {
System.out.println(info);
}
});
app.lambdaMethod_1(new Param2() {
@Override
public void outInfo(String info) {
System.out.println(info);
}
});
app.lambdaMethod_2(new Param1() {
@Override
public void outInfo(String info) {
System.out.println(info);
}
}, 1);
app.lambdaMethod_2(new Param2() {
@Override
public void outInfo(String info) {
System.out.println(info);
}
}, 2);
app.lambdaMethod_3(new Param3() {
@Override
public void outInfo(String info, int index) {
System.out.println(info + "#############" + index);
}
}, 3);
app.lambdaMethod_3(new Param4() {
@Override
public void outInfo(String info, int index) {
System.out.println(info + "#############" + index);
}
}, 4);
System.out.println("--------------------------------------------------------------------------");
app.lambdaMethod_1((Param1) info -> {
System.out.println(info);
});
app.lambdaMethod_1((Param2) info -> {
System.out.println(info);
});
app.lambdaMethod_2((Param1) info -> {
System.out.println(info);
}, 3);
app.lambdaMethod_2((Param2) info -> {
System.out.println(info);
}, 4);
app.lambdaMethod_3((Param3) (info, index) -> {
System.out.println(info + "#############" + index);
},5);
app.lambdaMethod_3((Param4) (info, index) -> {
System.out.println(info + "#############" + index);
},5);
}
}