:: (double colon) operator in Java 8

前端 未结 17 2829
旧时难觅i
旧时难觅i 2020-11-21 11:10

I was exploring the Java 8 source and found this particular part of code very surprising:

//defined in IntPipeline.java
@Override
public fin         


        
17条回答
  •  时光说笑
    2020-11-21 11:54

    return reduce(Math::max); is NOT EQUAL to return reduce(max());

    But it means, something like this:

    IntBinaryOperator myLambda = (a, b)->{(a >= b) ? a : b};//56 keystrokes I had to type -_-
    return reduce(myLambda);
    

    You can just save 47 keystrokes if you write like this

    return reduce(Math::max);//Only 9 keystrokes ^_^
    

提交回复
热议问题