匿名内部类的调用
Lambda关键词:
alt+回车
Lambda就是优化匿名内部类的
public main (){
int i=calculateNum(new IntBinaryOperator(){
@Override
public int applyAsInt(int left,int right){
return left+right;
}
})
}
public static int calculateNum(IntBinaryOperator intBinaryOperator){
int a=10;
int b=20;
return intBinaryOperator.applyAsInt(a,b);
}
修改成lambda
public main (){
int i=calculateNum((int left,int right)->{
return left+right;
}
})
}
public static int calculateNum(IntBinaryOperator intBinaryOperator){
int a=10;
int b=20;
return intBinaryOperator.applyAsInt(a,b);
}