类不能带有public、private访问权限。package-info.java再怎么特殊,也是一个类文件,也会被编译成package-info.class,但是在package-info.java中只能声明默认访问权限的类,也就是友好类。
Javac中与package-info相关的命令有:
-Xpkginfo:[always,legacy,nonempty]
Control whether javac generates package-info.class files from package-info.java files. Possible mode arguments for this option include the following.
- (1)always
-
Always generate a
package-info.classfile for everypackage-info.javafile. This option may be useful if you use a build system such as Ant, which checks that each.javafile has a corresponding.classfile. (2)legacy -
Generate a
package-info.classfile only if package-info.java contains annotations. Don't generate apackage-info.classfile if package-info.java only contains comments.Note: A
package-info.classfile might be generated but be empty if all the annotations in the package-info.java file haveRetentionPolicy.SOURCE. (3)nonempty -
Generate a
package-info.classfile only if package-info.java contains annotations withRetentionPolicy.CLASSorRetentionPolicy.RUNTIME.
本文探讨了在Java中如何正确使用package-info.java文件,包括其语法限制和与之相关的javac编译器选项。文章详细解释了三种不同的模式(always、legacy、nonempty),这些模式控制着是否及何时从package-info.java生成package-info.class文件。
1753

被折叠的 条评论
为什么被折叠?



