我只是在尝试学习一些DB_HOST=192.168.10.10
DB_DATABASE=homestead
DB_USERNAME=homestead
内容,并且遇到了这个脚本。
java-8
哪个好看。但我的问题是,而是采用这两行代码
public class ConstructorTest {
public static void main(String[] args) {
PersonFactory<Person> personFactory = Person::new;
Person person = personFactory.create("Test", "User");
System.out.println(person);
}
}
interface PersonFactory<P extends Person> {
P create(String firstName, String lastName);
}
class Person {
private String firstName;
private String lastName;
Person() {}
Person(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; }
@Override
public String toString() {
return "FirstName -> "+firstName + " : LastName ->"+ lastName;
}
}
我最好能够使用PersonFactory<Person> personFactory = Person::new;
Person person = personFactory.create("Test", "User");
System.out.println(person);
关键字创建我的Person
对象吗?
new
那么通过提供此Person person = new Person("Test", "User");
来增加此java-8
的优势是什么?
提前致谢。