Package-info.java documentation

Source: Internet
Author: User

Package-info.java documentation

Package-info.java documentation


1. Introduction to pacakge-info.java

A pacakge-info.java is a Java file that can be added to any Java source package. The goal of the pacakge-info.java is to provide either a package-level documentation or a package-level annotation.

In the pacakge-info.java file, the only requirement to contain content is the package statement, such:

Package com. ch. service;


Ii. Package documentation

Before Java 5, the package.html document is generated through JavaDoc. In Java 5 and later versions, the Package Description and related documents can be written into the pacakge-info.java file, it is also used to generate JavaDoc. For example:

 
  1. /**
  2. * Dev1.ch Package Description <br>
  3. * Tool libraries encapsulated based on the Apache DbUtils library to simplify development
  4. * @ Author Li Qiang <br>
  5. * Date: 2015.5.13
  6. * @ Since 1.7
  7. * @ Version 1.0
  8. *
  9. */
  10. Package dev1.ch;

The above description is generated through JavaDoc as follows:

Click the link of the dev1.ch package to display:

3. Package comments

Annotations are important to programmers, and pacakge-info.java files contain package-level annotations. We can also use ElementType to customize annotations.

The PACKAGE annotation is of course ElementType. PACKAGE. In addition, there are:

ElementType. TYPE (class, interface, enum)

ElementType. FIELD (instance variable)

ElementType. METHOD ElementType. PARAMETER

ElementType. CONSTRUCTOR

ElementType. LOCAL_VARIABLE

ElementType. ANNOTATION_TYPE (applied to another annotation)


For example, to Deprecate all types in the package, you can annotate each individual type (class, interface, enumeration, etc.) as follows:

 
  1. @DEPRECATED
  2. PUBLIC CLASS CONTACT {
  3. }

Or you can use the @ Deprecated annotation in the package-info.java package declaration file, which makes everything in the package obsolete.

 
  1. @Deprecated
  2. package dev1.ch.domain;


4. Add the package-info.java to the package

You can manually create a package-info.java file in the package directory, or you can achieve this through Eclipse tools.

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.