如何做功能组合?
在不耐烦地等待Java 8发布并在阅读了Brian Goetz的精彩“Lambda状态”文章后,我注意到函数组合根本没有涵盖。
根据上面的文章,在Java 8中,以下应该是可能的:
// having classes Address and Person
public class Address {
private String country;
public String getCountry() {
return country;
}
}
public class Person {
private Address address;
public Address getAddress() {
return address;
}
}
// we should be able to reference their methods like
Function<Person, Address> personToAddress = Person::getAddress;
Function<Address, String> addressToCountry = Address::getCountry;
现在,如果我想编写这两个函数以具有映射到国家/地区的函数,那么如何在Java 8中实现这一点?Person