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

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

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

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

三个作用:

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

  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-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. 如何创建:

参考

转载于:https://juejin.im/post/5c99dbe5f265da60d240a2c2

你可能感兴趣的文章
iOS数据持久化存储之归档NSKeyedArchiver
查看>>
JavaScript面向对象
查看>>
Intellij修改模板代码
查看>>
2.页面布局示例笔记
查看>>
C++命名法则
查看>>
一些老游戏CPU 100%占用的解决方法
查看>>
f5基本介绍
查看>>
博前语
查看>>
Java SE核心之一:常用类,包装类,其他基本数据类型包装类。
查看>>
郑捷《机器学习算法原理与编程实践》学习笔记(第二章 中文文本分类(一))...
查看>>
python (ploit)
查看>>
Android 用achartengine 画折线图怎么显示不正确
查看>>
js 点击button跳转页面
查看>>
程序简单的测试与升级(暨实践第一次作业)
查看>>
数据的奇偶校验
查看>>
java 应用程序的打包发行
查看>>
信号处理
查看>>
浏览器调用摄像头
查看>>
socket,tcp,http三者之间的区别和原理
查看>>
【100题】第五十九题 用C++编写不能被继承的类
查看>>