博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
什么是package-info.java
阅读量:4088 次
发布时间:2019-05-25

本文共 1394 字,大约阅读时间需要 4 分钟。

在java项目中创建package以后,可以在package下放一个package-info.java文件。

这个文件有什么作用?如何生成?

三个作用:

  1. 为标注在包上Annotation提供便利;

    package annotations

  2. 声明友好类和包常量;

比如一个包中有很多的内部访问的类或常量,就可以统一的放到package-info类中,这样就方便,而且集中管理,减少friendly类到处游走的情况,看例子:

//这里是包类,声明一个包使用的公共类,强调的是包访问权限class PkgClass{    public void test(){    }}//包常量,只运行包内访问,适用于分“包”开发class PkgConst{    static final String PACAKGE_CONST="ABC";}
  1. 提供包的整体注释说明。

Package Documentation

Prior to Java 5, package level documentation (the documentation shown in Javadocs for a package) was placed in package.html. Today, the description and other related documentation for a package can be written up in the package-info.java file and it gets used in the production of the Javadocs. As a demonstration, the example package-info.java…

/** * Domain classes used to produce the JSON and XML output for the RESTful services. * 

* These classes contain the JAXB annotations. * * @since 1.0 * @author jwhite * @version 1.1 */package com.intertech.cms.domain;

… results in the following Javadocs.

package documentation

package-info.java’s purpose

The package-info.java is a Java file that can be added to any Java source package. Its purpose is to provide a home for package level documentation and package level annotations. Simply create the package-info.java file and add the package declaration that it relates to in the file. In fact, the only thing the package-info.java file must contain is the package declaration.

  1. 如何创建:

create package.java

参考

转载地址:http://dubii.baihongyu.com/

你可能感兴趣的文章
MySQL的功能依赖检测功能
查看>>
HashMap
查看>>
替换空格
查看>>
得到单链表逆序遍历的结果
查看>>
反转单链表
查看>>
链表中倒数第k个节点
查看>>
合并两个有序单链表
查看>>
两个单链表的第一个公共节点
查看>>
链表中环的入口节点
查看>>
复杂链表的复制
查看>>
leetcode 200. Number of Islands(岛屿的数量)
查看>>
leetcode 130. Surrounded Regions(被围绕的区域)
查看>>
leetcode 733. Flood Fill
查看>>
leetcode 695. Max Area of Island(岛屿的最大面积)
查看>>
Scrum框架概述
查看>>
验证IP地址
查看>>
【转载】从JVM角度看Java多态
查看>>
数据库基础概念总结
查看>>
【牛客网】SQL练习
查看>>
跑马问题--36匹马,跑道每次最多只能有6匹马进行比赛,最少进行多少次比赛能比出前3名?
查看>>