当前位置:网站首页>Understanding of class
Understanding of class
2022-07-03 07:21:00 【four thousand three hundred and forty-three】
package JavaReflcet;
import org.junit.Test;
public class ClassTest {
/*
obtain Class The way of example
*/
@Test
public void test1() throws ClassNotFoundException {
// Mode one : Call the properties of the runtime class : .class
Class clazz = person.class;
System.out.println(clazz);
// The way 2: Through the object of the runtime class
person p1 = new person();
Class<? extends person> clazz2 = p1.getClass();
System.out.println(clazz2);
// The way 3: call Class Static method of :forName(String classPath)
Class clazz3 =Class.forName("JavaReflcet.person");
System.out.println(clazz3);
// The way 4: Using loaders for classes :ClassLoader
ClassLoader classLoader = ReflactionTest.class.getClassLoader();
Class<?> clazz4 = classLoader.loadClass("JavaReflcet.person");
System.out.println(clazz4);
}
}
person The runtime class of can be regarded as a singleton :
clazz == clazz2 //true
clazz2== clazz3 //true
边栏推荐
- [set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
- Use of generics
- Talk about floating
- The underlying mechanism of advertising on websites
- Interfaces and related concepts
- 691. Cube IV
- Wireshark software usage
- Advanced API (multithreading)
- Circuit, packet and message exchange
- Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
猜你喜欢
JS monitors empty objects and empty references
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
最全SQL与NoSQL优缺点对比
Wireshark software usage
Interfaces and related concepts
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Summary of abnormal mechanism of interview
High concurrency memory pool
Topic | synchronous asynchronous
随机推荐
Summary of Arduino serial functions related to print read
Talk about floating
Upgrade CentOS php7.2.24 to php7.3
JUC forkjoinpool branch merge framework - work theft
Shim and Polyfill in [concept collection]
Recursion, Fibonacci sequence
Advanced APL (realize group chat room)
Selenium key knowledge explanation
Advanced API (batch image Download & socket dialog)
Gridome + strapi + vercel + PM2 deployment case of [static site (3)]
Margin left: -100% understanding in the Grail layout
JMeter test result output
PHP install composer
Distributed lock
sharepoint 2007 versions
CentOS switches and installs mysql5.7 and mysql8.0
Discussion on some problems of array
JS date comparison
Common problems in io streams
你开发数据API最快多长时间?我1分钟就足够了