</pre><pre name="code" class="cpp">Java注解主要是附加代码中的信息,与注释不一样。
注解用于编译,运行时,以及使用,起到说明、配置的功能。
@Target @Retention @Documented @Inherited
<span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', 微软雅黑, sans-serif; font-size: 16px; line-height: 28.799999237060547px; text-indent: 16px;">@Retention: 定义注解的保留策略 </span><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', 微软雅黑, sans-serif; font-size: 16px; line-height: 28.799999237060547px; text-indent: 16px;">@Target:定义注解的作用目标 </span>
<span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', 微软雅黑, sans-serif; font-size: 16px; line-height: 28.799999237060547px; text-indent: 16px;"><span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', 微软雅黑, sans-serif; font-size: 16px; line-height: 28.799999237060547px; text-indent: 16px;">@Document:说明该注解将被包含在javadoc中 <span style="color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', 微软雅黑, sans-serif; font-size: 16px; line-height: 28.799999237060547px; text-indent: 16px;">@Inherited:说明子类可以继承父类中的该注解 详情参考博客【1】。</span></span></span>
</pre><pre name="code" class="cpp">
</pre><pre name="code" class="cpp">@beta注解:要考虑到要有更新操作。使用添加注释的beta-API一般是安全的。
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.ANNOTATION_TYPE,
ElementType.CONSTRUCTOR,
ElementType.FIELD,
ElementType.METHOD,
ElementType.TYPE})
@Documented
@GwtCompatible
public @interface Beta {}
说明了: 返回一个GWT序列化类型.
@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@GwtCompatible
public @interface GwtCompatible {
</pre><pre name="code" class="cpp">boolean serializable() default false;
boolean emulated() default false;
}
/**
* 说明一个方法可能无法与 GWT 一起使用
* 他只能用于被 @GwtCompatible 标志的类的字段,方法和内部类
*/
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.TYPE, ElementType.METHOD,
ElementType.CONSTRUCTOR, ElementType.FIELD })
@Documented
@GwtCompatible
public @interface GwtIncompatible {
/**
* 用于表示不兼容 GWT 的原因
*/
String value();
}