In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of java's way of obtaining class, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this java to obtain class. Let's take a look at it.
Acquisition mode
1. The specific class is known, and obtained through the class attribute of the class, this method is the most secure and reliable, and the program performance is the highest.
2. If you know an instance of a class, call the getclass () method of the instance to get the Class object.
3. The full class name is known, and this class can be obtained through the static method forName () of the Class class under the classpath. ClassNotFoundException may be thrown, which is more commonly used.
4. Through the class loader.
Example
@ Testpublic void test2 () throws ClassNotFoundException {/ / method 1: call the properties of the runtime class:. Class Class clazz1 = Person.class; System.out.println (clazz1); / / class cn.bruce.java.Person / / method 2: through the object of the runtime class, call getClass () Person p1 = new Person (); Class clazz3 = Class.forName ("cn.bruce.java.Person"); System.out.println (clazz3) / / class cn.bruce.java.Person System.out.println (clazz1 = = clazz2); / / true System.out.println (clazz1 = = clazz3); / / true / / Mode 4: use the class loader: ClassLoader (understand) ClassLoader classLoader = ReflectionTest.class.getClassLoader (); Class clazz4 = classLoader.loadClass ("cn.bruce.java.Person"); System.out.println (clazz4); / / class cn.bruce.java.Person System.out.println (clazz1 = = clazz4) / / true} this is the end of the article on "how does java get class?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "how java acquires class". If you want to learn more, you are welcome to follow the industry information channel.
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.