You use the Lambda syntax to implement the getCar() method of the getCar() interface, where the following anonymous class program is omitted using the concise Lambda syntax:
Rideable rideable = new Rideable() { @Override public Car getCar(String name) { return new Car(name); } };
This is Java 7 code. You can achieve the same using the Lambda expression:
Rideable rider = name -> new Car(name);
Or as in your example, using the method link:
Rideable rider = Car::new;
As a result, the getCar(String) method of the getCar(String) object can be used as new Car(String) .
And as the answer to your question, you create an instance of the Car class that implements the Rideable interface. This is another way to implement an interface without using the implement keyword.
If you think:
Car auto = Car("MyCar")::new;
or
Car auto = Car::new; Car vehicle = auto::getCar("MyCar");
or
Car vehicle = Rideable::new::getCar("MyCar");
All of these examples are wrong approaches. I have given you these examples because these are common mistakes that can be made when we talk about lambda expressions or a method.
source share