#Java注解(Annotations) @(Java)[annotations] 注解的作用分为
- 编写文档
- 代码分析
- 编译检查
基本内置注释
- @Overwrite 重写父类方法
- @Deprecated 不推荐使用
- @SuppressWarnings 警告提示,参数值有deprecation、unchecked、fallthrough、serial、finally
自定义注解 @interface类,有参数方法、有明确的target、保持性策略、文档化@Documented
并发注解
- @Immutable 不可变得
- @ThreadSafe 线程安全
- @NotThreadSafe 非线程安全
以上是作用到类上的。
GuardedBy(lock)是作用到域和方法上的,其有以下形式:
1、@GuardedBy( "this" ) 受对象内部锁保护
2、@GuardedBy( "fieldName" ) 受 与fieldName引用相关联的锁 保护。
3、@GuardedBy( "ClassName.fieldName" ) 受 一个类的静态field的锁 保存。
4、@GuardedBy( "methodName()" ) 锁对象是 methodName() 方法的返值,受这个锁保护。
5、@GuardedBy( "ClassName.class" ) 受 ClassName类的直接锁对象保护。而不是这个类的某个实例的锁对象。