java info是什么_什么是package-info.java
在java項目中創建package以后,可以在package下放一個package-info.java文件。
這個文件有什么作用?如何生成?
三個作用:
為標注在包上Annotation提供便利;
聲明友好類和包常量;
比如一個包中有很多的內部訪問的類或常量,就可以統一的放到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.
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.
如何創建:
參考
總結
以上是生活随笔為你收集整理的java info是什么_什么是package-info.java的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: second life 新手必读 原文h
- 下一篇: SQL Server2017数据库查询实