Java Custom Annotations

Source: Internet
Author: User

=================================================================

When there is only one member, the member name must be taken as value (). You can assign a value directly when you use it!

Use the following:

=======================================

Note Classes can have no members, called identity annotations.

Use the following:

=======================

Annotations cannot be used for annotations of classes if the annotation scope has only methods and no classes:

Error in class use!

If the annotation scope has only classes, then annotations cannot be used for methods!

@Target defines a scope, preceded by a method, followed by a class.

================================================

Life cycle:

If the lifetime of the annotation is set to source, the runtime annotations will not exist, and the console will not have the parse result unless the source code is present:

If you change to class:

Must be an explanation of what the runtime is able to extract:

=====================

Inheritance of annotations:

Because it is an interface, inheritance does not work and the console has no output. The way to inherit from an interface does not work, and then it changes to a class to see: Changing the Person class to the Class,child class inherits the person class.

Console output:

Summary: Annotations inherit only the annotations above the class and do not inherit annotations on the method.

Java Custom 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.