I have a class
public class Person { private int age; }
And using Supplier in java 8, I can save the link to the constructor, for example
Supplier<Person> personSupplier = Person::new
But what if my constructor accepts the age parameter as
public class Person { private int age; public Person(int age) {this.age = age;} }
Now
Supplier<Person> personSupplier = Person::new
doesn't work, so what should be the correct signature for personSupplier ? Obviously, I can do something like.
Supplier<Person> personSupplier = () -> new Person(10);
But for each person, age must be different, so he does not solve my problem.
Maybe I should use something else instead of Supplier ?
source share