I would like to ask about the following piece of code related to Functional Interfaces. I am confused by:
Rideable rider = Car :: new
Is it creating a Rideable
(interface) or Car
(class) instance?
If it is creating a Car
object, the constructor new Car()
(i.e. with no arguments) should be not existing, then how come this can be valid?
I Have been reading through this tutorial ,but still could not figure it out.
@FunctionalInterface
interface Rideable {
Car getCar (String name);
}
class Car {
private String name;
public Car (String name) {
this.name = name;
}
}
public class Test {
public static void main(String[] args) {
Rideable rider = Car :: new;
Car vehicle = rider.getCar("MyCar");
}
}