package-info.java_什么是package-info.java

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

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

三个作用:

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

声明友好类和包常量;

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

//这里是包类,声明一个包使用的公共类,强调的是包访问权限

class PkgClass{

public void test(){

}

}

//包常量,只运行包内访问,适用于分“包”开发

class PkgConst{

static final String PACAKGE_CONST="ABC";

}

复制代码提供包的整体注释说明。

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.

2798a050992886348326dde430cbe338.png

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.

如何创建:

419b29089eba26cb8c42f6f4a5814a63.png

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值