Java annotation Annotations

Source: Internet
Author: User

Reference: Java Official document http://docs.oracle.com/javase/specs/jls/se7/html/jls-9.html#jls-9.6

Annotation type:

is a special type of interface, except that the annotation declaration is @interface

Features:

1.Java annotations cannot explicitly declare a parent class (in fact they all inherit the annotation class, but you cannot use the extends keyword when declaring), nor can it be generalized.

2. Method:

a) Each method defines an element in the annotation (each of the methods declaration in an annotation type declaration defines an Element of the annotation type).

b) The method parameter in the annotation can not have parameters

c) Methods in annotations can not throw exceptions

d) The return value of the method (that is, the element of the annotation) must be one of the following:a primitive type (base type: int, float, etc.),String, Class, parameterized invocation ofClass, enum, Annotation,array

(parameterized invocation Class of: After Java 5 java.lang.Class is a generic class, meaning that he can have type parameters, specifically refers to the form of class<...>, for example: class< extends formatter> value (); )

e) If the declaration of a method does not have the default keyword, it must be assigned using the generic type

D) If you want to create a framework that calls annotations through reflection during run time, you need your annotations annotated @retention (retentionpolicy.runtime), otherwise the annotations may be eliminated during compilation.


3. if no special declaration, annotations and interface (all static fields)

Java annotation Annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.