当前位置:网站首页>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 .
边栏推荐
- Sword finger offer (IX): abnormal jumping steps
- Kubernetes flannel: host-gw mode
- 银行业客户体验管理现状与优化策略分析
- JSON data transfer parameters & date type parameter transfer
- Extra(5)—mysql执行计划(五十一)
- 8 年产品经验,我总结了这些持续高效研发实践经验 · 研发篇
- 冒泡排序的时间复杂度分析
- 基于ASP.NET的某高校学院档案管理系统
- 多线程使用不当导致的 OOM
- B+ tree index use (8) sorting use and precautions (20)
猜你喜欢

HCIP第十一天比较(BGP的配置、发布)

Elementary notes of binary tree

Target detection network r-cnn series

Kubernetes apiserver current limiting strategy

Solution 5g technology helps build smart Parks

Win11+VS2019配置YOLOX

A college archives management system based on asp.net
![[applet] why can't the onreachbottom event be triggered? (one second)](/img/da/3641040c63f6db4d227dcf2ff89919.png)
[applet] why can't the onreachbottom event be triggered? (one second)

Shutter background graying effect, how transparency, gray mask

Student examination system based on C #
随机推荐
LeetCode 217. 存在重复元素
The parent component accesses the methods or parameters of the child component (the child component exposes the method defineexpose)
Router. Push(), router. Reply(), router. Go()
如何面对科技性失业?
JSON format execution plan (6) - MySQL execution plan (52)
PostgreSQL official website download error
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light
我们被一个 kong 的性能 bug 折腾了一个通宵
Golang port scanning design
父组件访问子组件的方法或参数 (子组件暴漏出方法defineExpose)
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
LeetCode 2119. 反转两次的数字
The difference between $route and $route
Emotion analysis model based on Bert
Use positioning to realize left, middle and right layout, and the middle content is adaptive
Leetcode 217. there are duplicate elements
Kubernetes Flannel:HOST-GW模式
Mysql数据目录(2)---表数据结构(二十五)
Shutter cachednetworkimage fillet
B+ tree index use (8) sorting use and precautions (20)