:: (double colon) operator in Java 8

前端 未结 17 3466
旧时难觅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:39

    The :: is known as method references. Lets say we want to call a calculatePrice method of class Purchase. Then we can write it as:

    Purchase::calculatePrice
    

    It can also be seen as short form of writing the lambda expression Because method references are converted into lambda expressions.

提交回复
热议问题