Eclipse Juno - package-info.java 有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12599058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 19:04:21  来源:igfitidea点击:

Eclipse Juno - What is the use of package-info.java?

javaeclipse

提问by IMJS

When a new package is being created in Eclipse Juno, a java file (package-info.java) would be created automatically. What is the use of that file? Is it useful in importing specific classes in another class?

在 Eclipse Juno 中创建新包时,会自动创建一个 java 文件 (package-info.java)。那个文件有什么用?在另一个类中导入特定类有用吗?

采纳答案by Philipp Cla?en

It can be used for documentation on package level. For instance, the Spring Team uses it quite extensively in the core of the Spring Framework.

它可用于包级别的文档。例如,Spring 团队在 Spring 框架的核心中非常广泛地使用它。

Beside that, it can contain annotations that apply to all classes in the package. For instance, it is a convenient way to avoid writing the NonNullByDefaultannotations for the Eclipse Null Analysis on each class.

除此之外,它还可以包含适用于包中所有类的注释。例如,这是一种避免在每个类上为 Eclipse Null 分析编写NonNullByDefault注释的便捷方法。

Note that for applying an annotation to a package, a file by the name package-info.java is used.

请注意,为了将注释应用于包,使用名为 package-info.java 的文件。

回答by David Grant

package-info.javais a package comment file, used by Javadoc for giving your package its own documentation.

package-info.java是一个包注释文件,Javadoc 使用它来为您的包提供自己的文档。

It was introduced in Javadoc 5.0, and replaces package.html.

它是在 Javadoc 5.0引入的,并取代了package.html.

回答by Ami

package-info.java file contains package level documentation as well as annotations.

package-info.java 文件包含包级文档以及注释