Java custom annotations

Posted on 2013-08-12 15:13  chayu3  阅读(227)  评论(0编辑  收藏  举报

Custom annotation definition is similar as Interface, just with @ in front. Annotation interface itself can have or have not annotations. @Retention(RetentionPolicy.RUNTIME) means VM will retain annotation with this type so they can be read reflectively at run-time.

Java defines a set of annotations that are build into the language:

Annotations applied to Java code: 1, @Override  2, @Deprecated  3, @SuppressWarnings

Annotations applied to other annotations: 1, @Retention(specifies how the marked annotation is stored)   2, @Documented  3, @Target(specifies where this annotation can be applied to)   4, @Inherited

Unlike interface method declarations, custom annotation have method like "int retryCount() default 5;", "default" keyword is only for java annotations. If you want to use another value, when using this custom annotation, @FluentInterface(retryCount=6).