当前位置:网站首页>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
边栏推荐
猜你喜欢
SecureCRT password to cancel session recording
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
POI excel percentage
Final, override, polymorphism, abstraction, interface
Interfaces and related concepts
Custom generic structure
Le Seigneur des anneaux: l'anneau du pouvoir
[solved] unknown error 1146
高并发内存池
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
随机推荐
[solved] unknown error 1146
JS monitors empty objects and empty references
Advanced API (byte stream & buffer stream)
OSI knowledge sorting
20220319
Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
Thoughts on project development
“百度杯”CTF比赛 2017 二月场,Web:爆破-1
Specified interval inversion in the linked list
"Moss ma not found" solution
Strategy mode
Advanced API (use of file class)
万卷书 - 价值投资者指南 [The Education of a Value Investor]
C代码生产YUV420 planar格式文件
Book recommendation~
专题 | 同步 异步
Spa single page application
Talk about floating
Laravel frame step pit (I)
2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log