当前位置:网站首页>Brief introduction of reflection mechanism
Brief introduction of reflection mechanism
2022-07-26 13:22:00 【Suzerk】
Reflection is Java Seen as the key to dynamic language , The reflection mechanism allows programs to use reflection during execution API Get internal information about any class , And can directly operate the internal properties and methods of any object .
obtain Class Common methods of objects :
Class c=Class.forName("java.lang.String");
Even if it's private Modified keywords can also be read .
function :
1) Judge the member variables and methods of any class at run time ;
2) Get generic information at runtime ;
3) Processing annotations at run time ;
4) Generate dynamic agents ;
5) At run time, determine the class that any object belongs to ;
6) Construct an object of any class at run time ;
instanceofUsed to determine whether it is an instance of a class :
System.out.println(Class.forName(properties.getProperty("FactoryName")).newInstance() instanceof IFactory );
- Use
newInstance()Method to createClassObject corresponds to an instance of the class .
IFactory operFactory = (IFactory) Class.forName("AddFactory").newInstance();
- Advantages and disadvantages :
advantage :
1) It improves the flexibility and expansibility of the program , Reduce module coupling ;
2) Get the various contents of the class at run time , Method of calling object .
3) Using reflection prevents code from being written dead in the framework .
shortcoming :
1) Reflection consumes a certain amount of system resources , The efficiency of reflection operation is much lower than that of normal operation ;
2) The permission check can be ignored when the reflection calls the method , As a result, encapsulation may be broken and security problems may arise .
边栏推荐
- How to face scientific and technological unemployment?
- 多线程使用不当导致的 OOM
- Flutter integrated Aurora push
- One stroke problem (Chinese postman problem)
- Outline design specification
- 《Kotlin系列》之MVVM架构封装(kotlin+mvvm)
- Kubernetes APIServer 限流策略
- 【花雕动手做】有趣好玩的音乐可视化系列小项目(12)---米管快速节奏灯
- 维度灾难 维数灾难 暂记
- 12 brand management of commodity system in gulimall background management
猜你喜欢

PostgreSQL official website download error

How to build a customer-centric product blueprint: suggestions from the chief technology officer

多线程使用不当导致的 OOM

HCIP第十二天笔记整理(BGP联邦、选路规则)

How to face scientific and technological unemployment?

Solution: unable to load the file c:\users\user\appdata\roaming\npm\npx PS1, because running scripts is prohibited on this system.
![[5gc] what is 5g slice? How does 5g slice work?](/img/8c/52ba57d6a18133e97fa00b6a7cf8bc.png)
[5gc] what is 5g slice? How does 5g slice work?

12-GuliMall 后台管理中商品系统的品牌管理

【花雕动手做】有趣好玩的音乐可视化系列小项目(13)---有机棒立柱灯

flutter多渠道打包运行
随机推荐
Solve the problem that the remote host cannot connect to the MySQL database
Kubernetes apiserver current limiting strategy
12-GuliMall 后台管理中商品系统的品牌管理
MySQL data directory (2) -- table data structure (XXV)
基于C#实现的学生考试系统
key&key_ Len & ref & filtered (4) - MySQL execution plan (50)
vector的一些实用操作
异步线程池在开发中的使用
JVM: what does the class loading subsystem do? What is it made of? What eight part essay do you need to remember?
[upper computer tutorial] Application of integrated stepping motor and Delta PLC (as228t) under CANopen communication
Mysql数据目录(2)---表数据结构(二十五)
B+树(3)聚簇索引,二级索引 --mysql从入门到精通(十五)
Sword finger offer (x): rectangular coverage
1312_适用7z命令进行压缩与解压
Research status and pain points of deep learning 3D human posture estimation at home and abroad
LeetCode 2119. 反转两次的数字
[applet] why can't the onreachbottom event be triggered? (one second)
Reflection, an implementation of automatic repeated call interface
概率论与数理统计
HCIP第十二天笔记整理(BGP联邦、选路规则)