当前位置:网站首页>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 .
边栏推荐
- R语言使用rchisq函数生成符合卡方分布的随机数、使用plot函数可视化符合卡方分布的随机数(Chi Square Distribution)
- [depth first search] Ji suanke: find numbers
- Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform
- 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
- R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
- Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
- A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
- How to type multiple spaces when editing CSDN articles
- Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan
- Use of deg2rad and rad2deg functions in MATLAB
猜你喜欢

Detailed idea and code implementation of infix expression to suffix expression

How word displays modification traces

An error occurs when installing MySQL: could not create or access the registry key needed for the

中缀表达式转后缀表达式详细思路及代码实现

Don't miss this underestimated movie because of controversy!

Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
Benefit a lot, Android interview questions

五金机电行业供应商智慧管理平台解决方案:优化供应链管理,带动企业业绩增长

Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform

谷粒商城--分布式高级篇P129~P339(完结)
随机推荐
Oracle advanced (IV) table connection explanation
Camel case with Hungarian notation
[paper notes] transunet: transformers make strongencoders for medical image segmentation
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图
pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
R语言使用dt函数生成t分布密度函数数据、使用plot函数可视化t分布密度函数数据(t Distribution)
Excel 中VBA脚本的简单应用
test about BinaryTree
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
【pytorch】yolov5 训练自己的数据集
渲大师携手向日葵,远控赋能云渲染及GPU算力服务
Reptiles have a good time. Are you full? These three bottom lines must not be touched!
The dplyr package of R language performs data grouping aggregation statistical transformations and calculates the grouping mean of dataframe data
Test technology stack arrangement -- self cultivation of test development engineers
PMP每日一练 | 考试不迷路-7.6
USB host driver - UVC swap
今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发
R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置add参数为不同水平点状条带图添加箱图