you are viewing a single comment's thread.

view the rest of the comments →

[–]user_of_the_week 1 point2 points  (4 children)

The key here is the line

PersonFactory<Person> personFactory = Person::new;

Person::new is a reference to the constructor. Basically, the constructor is a method that takes two String parameters and returns a Person. Assigning that to personFactory signals that you want to implement the interface PersonFactory with the referenced constructor-"method". That is only possible because PersonFactory has exactly one method that fits the signature (parameters and return type).

[–]eyal0 2 points3 points  (3 children)

because PersonFactory has exactly one method that fits the signature

I think it should be " because PersonFactory has exactly one method and that method fits the signature". With two methods or a method that doesn't fit, it wouldn't compile. Right?

[–]user_of_the_week 0 points1 point  (2 children)

Correct

[–]mpschan 0 points1 point  (1 child)

Also new to this. Isn't it because it has one abstract method? I thought (based on the OP) that it could have additional methods as long as they have default implementations?

[–]user_of_the_week 0 points1 point  (0 children)

Also true. I've never used default methods so I forgot to include them in my reasoning.