In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
            
                    
                
2025-11-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail about java.util.function.* in java 8 Pojo reflection example analysis, Xiaobian think quite practical, so share to everyone for a reference, I hope you can read this article after some harvest.
Write an ordinary 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; }}
a conventional manner
// Use a constructor with parameters to create a CityCity sf = new City("San Francisco", "SF");// Use a default constructor with no parameters to create a CityCity la = new City();// Set the members using settersla.setName("Los Angeles");la.setCode("LA");
New getter access method
// Use the City's method references and assign them to functionsFunction getNameFunction = 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
New setter access method
// Use the City's method references and assign them to biconsumersBiConsumer setNameBiConsumer = City::setName;BiConsumer setCodeBiConsumer = City::setCode;City ny = new City();setNameBiConsumer.accept(ny, "New York");setCodeBiConsumer.accept(ny, "NY");
Visit constructor to create a new instance
// Use the City's constructor method reference to create// a default constructor reference.Supplier defaultConstructor = City::new;City sd = defaultConstructor.get();sd.setName("San Diego");sd.setCode("SD");
Parametric Builder
// Use the City's constructor method reference to create// a two-parameter constructor reference.BiFunction twoParameterConstructor = City::new;City dc = twoParameterConstructor.apply("Washington, D. C. ", "DC"); About" java.util.function.* in java8 Pojo reflection example analysis "This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





            
            About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.