In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is JAVA reflection". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is JAVA reflection".
What is reflex?
Reflection is to map the components of the Java class into Java objects one by one. That is, in the running state, for any class, you can know all the properties and methods of that class; for any object, you can call any of its methods and properties. This function of dynamically obtaining information and dynamically calling object methods is called Java reflection mechanism.
How to get the bytecode file of a class using the full path of the class Class clazz = Class.forName ("com.xuzhu.reflect.Person"); type .classClass clazz = Person.class; object .getClass () Person person = new Person (); Class clazz = person.getClass (); get all attributes of the class Field [] declaredFields = clazz.getDeclaredFields (); for (Field field: declaredFields) {String fieldName = field.getName (); System.out.println ("fieldName:" + fieldName) } get all the methods of the class Method [] declaredMethods = clazz.getDeclaredMethods (); for (Method method: declaredMethods) {String methodName = method.getName (); System.out.println ("methodName:" + methodName);} call method / / call setAge ()\ getAge () method Method setAge = clazz.getDeclaredMethod ("setAge", Integer.class); Object instance = clazz.newInstance (); setAge.invoke (instance, new Integer (1)); Method getAge = clazz.getDeclaredMethod ("getAge") System.out.println (getAge.invoke (instance)); thank you for reading, the above is the content of "what is JAVA reflection". After the study of this article, I believe you have a deeper understanding of what is JAVA reflection, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.