当前位置:网站首页>Reflection and illegalaccessexception exception during application
Reflection and illegalaccessexception exception during application
2022-07-06 19:20:00 【qq_ thirty-seven million seven hundred and five thousand five h】
First, learn about reflection :
Reflection : Encapsulate the components of a class into other objects , This is the reflection mechanism
After the bytecode file is loaded into memory , Will form a Class Class object
Here's how to get Class Three ways of objects :
Class.forName(” Full class name “): Load the bytecode file into memory , return Class object
More for configuration files , You can define the class name in the configuration file . Read the file and load the class
If bytecode file has been loaded into memory , Just pass the class name .Class To get
It is mainly used for parameter passing
An instantiated object already exists , Through the object .getClass() Method ,getClass Method inherited from Object class
It is mainly used for obtaining bytecode of objects
Conclusion : The same bytecode file (*.class) In a program run , It will only be loaded once , No matter which method you get Class Objects are member methods in the same source code 、 Member variables and constructors will be encapsulated into their corresponding array objects
adopt Class Object can get member variables respectively 、 Member methods and constructors :
Because the member method 、 The access modifiers of member variables and constructors are different
Different methods of obtaining may lead to the situation that private members cannot be obtained ,
The same thing , After getting the member variable 、 After member methods and constructors , Cannot directly operate on member variables, member methods and constructors modified by private permission modifiers
If you directly operate on the past private members , Will throw out IllegalAccessException abnormal
Solution : Ignore security checks for permission modifiers
Object obtained .setAccessible(true);
After getting the member method 、 Member variables 、 After the constructor , In the corresponding class method、Field、Constructor You can also further operate on the obtained object .
边栏推荐
- GCC【7】- 编译检查的是函数的声明,链接检查的是函数的定义bug
- PMP practice once a day | don't get lost in the exam -7.6
- Lucun smart sprint technology innovation board: annual revenue of 400million, proposed to raise 700million
- Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
- Take a look at how cabloyjs workflow engine implements activiti boundary events
- R language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
- 反射及在运用过程中出现的IllegalAccessException异常
- Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
- 黑马--Redis篇
- ROS自定义消息发布订阅示例
猜你喜欢
pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
【论文笔记】TransUNet: Transformers Make StrongEncoders for Medical Image Segmentation
RT-Thread 组件 FinSH 使用时遇到的问题
快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
[translation] a GPU approach to particle physics
提前解锁 2 大直播主题!今天手把手教你如何完成软件包集成?|第 29-30 期
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller
应用使用Druid连接池经常性断链问题分析
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
A method of removing text blur based on pixel repair
随机推荐
Interface test tool - postman
黑马--Redis篇
应用使用Druid连接池经常性断链问题分析
php+redis实现超时取消订单功能
CPU负载很低,loadavg很高处理方法
倒计时2天|腾讯云消息队列数据接入平台(Data Import Platform)直播预告
Abstract classes and abstract methods
swagger2报错Illegal DefaultValue null for parameter type integer
R语言使用dt函数生成t分布密度函数数据、使用plot函数可视化t分布密度函数数据(t Distribution)
tensorflow和torch代码验证cuda是否安装成功
How to type multiple spaces when editing CSDN articles
PMP practice once a day | don't get lost in the exam -7.6
How word displays modification traces
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置add参数为不同水平点状条带图添加箱图
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
ROS custom message publishing subscription example
Helm deploy etcd cluster
usb host 驱动 - UVC 掉包
About NPM install error 1