Method reference in Java 8

前端 未结 5 1104
梦如初夏
梦如初夏 2021-02-13 15:31
public class Car {

    private int maxSpeed;

    public Car(int maxSpeed) {
        this.maxSpeed = maxSpeed;
    }

    public int getMaxSpeed() {
        return maxS         


        
5条回答
  •  耶瑟儿~
    2021-02-13 16:29

    That is because the getMaxSpeed method is a Function.

    Namely:

     Comparator java.util.Comparator.comparing(
        Function keyExtractor
    )
    

    Note

    In order to reference getMaxSpeed from an instance of Car with the :: idiom, you would have to declare a Car method with signature: getMaxSpeed(Car car).

提交回复
热议问题