https://www.bilibili.com/video/BV1p4411P7V3
根据狂神视频简单记录。
1.内置注解
@Override:覆盖
@Deprecated:被弃置
@SuppressWarnings :压制警告
2.元注解
@Target:注解的使用范围 ElementType(TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE)
@Retention:注解的生命周期 RetentionPolicy(SOURCE<CLASS<RUNTIME)
@Document:该注解被包含在javadoc中
@Inherited:子类可以继承父类的该注解
3.自定义注解
@interface My Annotation{
String value();
}
4.获取Class类的实例
Person.class person.getClass() Class.forName()
5.类加载器
BootstrapClassloader ExtensionClassloader SystemClassloader 自定义Classloader
6.获取类的运行时结构
类名:getName getSimpleName
属性:getField getFields getDeclaredFields
方法:getMethod getMethods getDeclaredMethods
构造器:getConstructors getDeclaredConstructors
7.动态创建对象执行方法
constructor.newInstance()
method.invoke()
field.set()
setAccessible()
8.获得注解
getAnnotation()
getDeclaredAnnotation()