這篇文章將為大家詳細(xì)講解有關(guān)java8中java.util.function.*pojo反射的示例分析,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)公司專注于寧河網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供寧河營銷型網(wǎng)站建設(shè),寧河網(wǎng)站制作、寧河網(wǎng)頁設(shè)計(jì)、寧河網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造寧河網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供寧河網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
寫一個(gè)普通的POJO
public class City { private String name; private String code; public City() { } public City(String name, String code) { this.name = name; this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
傳統(tǒng)的方式
// Use a constructor with parameters to create a City City sf = new City("San Francisco", "SF"); // Use a default constructor with no parameters to create a City City la = new City(); // Set the members using setters la.setName("Los Angeles"); la.setCode("LA");
新的getter訪問方式
// Use the City's method references and assign them to functions FunctiongetNameFunction = City::getName; Function getCodeFunction = City::getCode; System.out.println("The code for " + getNameFunction.apply(sf) + " is " + getCodeFunction.apply(sf)); -> The code for San Francisco is SF
新的setter訪問方式
// Use the City's method references and assign them to biconsumers BiConsumersetNameBiConsumer = City::setName; BiConsumer setCodeBiConsumer = City::setCode; City ny = new City(); setNameBiConsumer.accept(ny, "New York"); setCodeBiConsumer.accept(ny, "NY");
訪問 constructor 創(chuàng)建新實(shí)例
// Use the City's constructor method reference to create // a default constructor reference. SupplierdefaultConstructor = City::new; City sd = defaultConstructor.get(); sd.setName("San Diego"); sd.setCode("SD");
帶參數(shù)的構(gòu)建器
// Use the City's constructor method reference to create // a two-parameter constructor reference. BiFunctiontwoParameterConstructor = City::new; City dc = twoParameterConstructor.apply("Washington, D. C.", "DC");
關(guān)于“java8中java.util.function.*pojo反射的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。