In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.