当字段或方法签名中的类的可见性不如使用它的成员的可见性时,报告该类的用法。
虽然此类成员是合法的 Java,但不能在它们引用的类类型的可见性作用域之外使用。
示例:
public class Parent {
public Child getChild() {
return new Child();
}
private class Child {}
}
此外,在 Java 9 和更高版本中,模块可以通过不导出它们的软件包来向其他模块隐藏它的某些类。
不过,如果属于导出的 API 的成员在其签名中引用了非导出类,则不能在模块外部使用此类成员。
配置检查:
- Use the Report non-exported classes exposed in module API (Java 9+) option to report module API members
that expose non-exported classes.
Note that the language level of the project or module needs to be 9 or higher for this option.
- 使用报告在公开 API 中公开的不可访问类选项可以报告公开可见性作用域较小的类的 public 成员。
- 使用报告在 package-local API 中公开的 private 类选项可以报告公开
private 类的 package-local 成员。