In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces what is the java reflection mechanism, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.
Java: "everything is the object". It feels like the java language itself is constantly practicing this sentence.
The basis of the java reflection mechanism comes from a Class class, and we can use the methods in this class to read, instantiate, and so on.
Object represents or encapsulates some data. After a class is loaded, jvm creates a Class object for the corresponding class (a class corresponds to only one Class object), and the entire structure information of the class is placed in the corresponding Class object. The Class object is like a mirror through which you can see all the information of the corresponding class.
Free video tutorials sharing: java video tutorials
For example:
The process of instantiating a Person:
Person person = new Person ()
Apply reflection to achieve:
Class clz = null;String name = "com.zl.server.Person"; / / the address of the class try {clz = Class.forName (name); / / pass the address of the class to Person person = (Person) clz.getConstructor (). NewInstance (); / / get the constructor and instantiate return servlet;} catch (Exception e) {e.printStackTrace ();}
The reflection mechanism makes class instantiation more flexible.
In many frameworks, reflection has been used a lot, and we can get the annotations, constructors, attributes and so on of the class through Class for more processing.
On what is the java reflection mechanism to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can 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.