Method reference in Java 8
public class Car { private int maxSpeed; public Car(int maxSpeed) { this.maxSpeed = maxSpeed; } public int getMaxSpeed() { return maxSpeed; } } We can sort a list of cars by, Car carX = new Car(155); Car carY = new Car(140); List<Car> cars = new ArrayList<>(); cars.add(carX); cars.add(carY); cars.sort(Comparator.comparing(Car::getMaxSpeed)); If we see the signature of … Read more