In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "what are the ways to use the Java reflection mechanism?" the content in the article 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 are the ways to use the Java reflection mechanism?"
What is the class class
In an object-oriented world, everything is an object. A class is an object, and a class is an instance object of the java.lang.Class class. In addition, only the java virtual machine can new the class class. Any class is an instance object of the Class class. This instance object can be expressed in three ways:
Public class User {} public class ClassTest {User u=new User (); / / method 1:Class c1roomUser.classbank / method 2:Class c2=u.getClass (); / / method 3:Class c3=Class.forName ("com.forezp.User"); / / you can create an instance object User user= (User) c1.newInstance () of that class through the type of the class;}
II. Dynamic loading of class
Class.forName (the full name of the class); this method represents not only the type of the class, but also the dynamically loaded class. The compile-time load class is statically loaded, and the run-time load class is dynamically loaded.
Third, obtain method information
The basic data types and the void keyword are instances of the Class class; you can get the name of the class through getame (); getSimpleName ().
Class c1roomString.classacultClass c2roomint.classscape Class c3roomvoid.classpoliticSystem.out.println (c1.getName ()); System.out.println (c2.getSimpleName ())
Get all the methods of the class and print them out:
Public static void printClassInfo (Object object) {Class c=object.getClass (); System.out.println ("class name:" + c.getName ()); / * A member method is a method object * getMethod () all public methods, including public* getDeclaredMethods () inherited by the parent class, gets all the methods of the class, including private, but does not include inherited methods. * / Method [] methods=c.getMethods (); / / get the method / / get all the methods, including private, c.getDeclaredMethods (); for (int iTuno
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.