当前位置:网站首页>2022-08-10 The sixth group Hiding spring study notes
2022-08-10 The sixth group Hiding spring study notes
2022-08-11 03:29:00 【Hot shin ramen】
活动地址:CSDN21天学习挑战赛
前言
Annotate today、反射的学习
JavaMost of the basic courses have been completed,Some small points left to add
️注解
注解:Annotation JDK1.5
public @interface MyAnnotation(){
}
Create your own annotations
Annotations also have annotations,元注解:Annotation added specifically to annotations
Retentionetc. are enumerations,后面跟的是常量
We found that annotations can have methods,可以有默认值
String name() default “Tom”;
定义方法格式:String name(); Do not write the default value, you need to assign,with default valuedefault指定默认值
public class Ch01{
@MyAnnotation(age=20) It can be understood as adding a return value
public void show(){
}
}
If there is only one, you don't need to write the name,If there are more than one need to write the name
在javain the entire annotation system,There are three very important trunk classes
1.Annotation 接口 Define some common methods
2.ElementType枚举 Used to specify the type of annotation (where to use annotations)
3.RetentionPolicy 枚举 The strategy used to specify annotations,Different types of policies specify different scopes
(1)SUTCE Annotations exist only during compiler processing,After compile time processing,这个注解就没有了
(2)CLASS 注解在.classstill valid in the file
(3)RUNTIME compile time doesn't work,only during runtimeJVM读取
Java自带注解
️作用在代码上的注解
[email protected],Check if a method is an overridden method,If it returns its parent class,Or if there is no such method in the referenced interface, an error will be reported
[email protected] Marked method is obsolete
[email protected] Tell the editor to ignore warnings
[email protected] Ignore any parameters used as generic variable method or constructor of warning
[email protected] Identifies an interface as a functional interface
[email protected] Identifies that an annotation can be used multiple times on the same declaration
all:忽略所有警告
boxing:Ignore boxing and unboxing warnings
rawtypes:Use generate without specifying data type
unchecked:Ignore warnings without type checking
unused:Ignore unused warnings
️元注解
[email protected] Identifies the scope of this annotation
[email protected] Marks whether this annotation is included in the user documentation
[email protected] What information can this annotation modify
[email protected] If a class uses this annotation ,那么其子类也会继承这个注解
️反射
Class类
You can get all the structures in the class,You can access class information without manipulating the class
1.直接使用类名.class
2.使用全类名
3.使用对象
Class<>When using generics, add
获取类的名字:clazz.getName()
获取类的加载器:
获取资源
URL resource = clazz.getResource(“”);
获取父类
clazz.getSuperclass()
Is it an array of interfaces?
clazz.isArray();
clazz.isInterface();
重点
Dog dog = clazz.newInstance(); jdk9过时
创建出dog一个对象:使用classclass object instantiates an object
clazz.getDeclaredConstructor().newInstance(); 代替 In the constructor method
对成员变量的操作:
对成员变量进行操作,只能获取到public修饰的属性
可以获取到private属性
get all properties
获取对象的属性
String str = (String)type.get(dog1); If you want a string, use coercion
给对象的属性赋值
Privatized things can also operate
反射调用方法???
通过反射来调用构造器
通过构造器创建对象
构造器私有化
sout(dog1.getName());
对注解的操作
️总结
Although reflection and annotation are not as difficult as multi-threading and other sections,But the importance cannot be ignored,For object creation we encourage the use of reflection to create,它允许程序创建和控制任何类的对象(根据安全性限制),无需提前硬编码目标类.这些特性使得反射特别适用于创建以非常普通的方式与对象协作的库.
业精于勤,荒于嬉; 行成于思,毁于随.
边栏推荐
- 调试技巧总结
- Is there any way for kingbaseES to not read the system view under sys_catalog by default?
- The 125th day of starting a business - a note
- pathman_config、pathman_config_params 删除后,如何重建?
- 2022-08-10 第六小组 瞒春 学习笔记
- Goodbye Chengdu paper invoices!The issuance of electronic invoices for accommodation expenses will soon completely replace the invoices of hotels, catering and gas stations
- Summary of debugging skills
- 创业的第125天——随记
- A brief analysis of whether programmatic futures trading or manual order is better?
- Qnet Weak Network Test Tool Operation Guide
猜你喜欢
MongoDB 基础了解(二)
EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
[idea error] Invalid target distribution: 17 solution reference
VIT 源码详解
互换性与测量技术-公差原则与选用方法
The most unlucky and the luckiest
What should I do if the channel ServerID is incorrect when EasyCVR is connected to a Hikvision Dahua device and selects another cluster server?
字体反扒
Add user error useradd: cannot open /etc/passwd
2022-08-10 第六小组 瞒春 学习笔记
随机推荐
多商户商城系统功能拆解26讲-平台端分销设置
EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
高校就业管理系统设计与实现
索引的创建、查看、删除
高度塌陷问题的解决办法
广州纸质发票再见!开住宿费电子发票即将全面取代酒店餐饮加油站发票
轮转数组问题:如何实现数组“整体逆序,内部有序”?“三步转换法”妙转数组
MYSQLg高级------回表
Add user error useradd: cannot open /etc/passwd
Goodbye Chengdu paper invoices!The issuance of electronic invoices for accommodation expenses will soon completely replace the invoices of hotels, catering and gas stations
正式发布丨VS Code 1.70
MongoDB 基础了解(二)
构建程序化交易系统需要注意什么问题?
CSDN 博客更换皮肤
程序化交易改变了什么?
Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use
AI+医疗:使用神经网络进行医学影像识别分析
21天学习挑战赛第一周总结
求和、计数的窗口函数应用
否定语义转化层