这篇文章
通过启用预览功能来完善Java介绍了为什么这个警告不能被禁用的主要目的。
想象一下,如果每个人都开始尝试预览功能(或者孵化器模块),然后传播那些代码和工件。当一个功能发生变化时,它们很快就会过时,维护这样的依赖关系将成为一场噩梦。不过,不用担心,有许多保障措施可以防止这种情况发生。至少,防止意外发生。
这个额外的链接展示了最新的Eclipse IDE支持哪些@SuppressWarning
值。
更新
这里是OpenJDK的源代码,证明了该警告始终处于启用状态。
Preview类的完整源代码
public class Preview {
private final boolean enabled;
private final MandatoryWarningHandler previewHandler;
private final boolean forcePreview;
private final Map<Integer, Source> majorVersionToSource;
private final Lint lint;
private final Log log;
private static final Context.Key<Preview> previewKey = new Context.Key<>();
public static Preview instance(Context context) {
Preview instance = context.get(previewKey);
if (instance == null) {
instance = new Preview(context);
}
return instance;
}
Preview(Context context) {
context.put(previewKey, this);
Options options = Options.instance(context);
enabled = options.isSet(PREVIEW);
log = Log.instance(context);
lint = Lint.instance(context);
this.previewHandler =
new MandatoryWarningHandler(log, lint.isEnabled(LintCategory.PREVIEW), true, "preview", LintCategory.PREVIEW);
forcePreview = options.isSet("forcePreview");
majorVersionToSource = initMajorVersionToSourceMap();
}
...
}
强制性在
MandatoryWarningHandler
的第三个参数(
enforceMandatory
)中被硬编码。
MandatoryWarningHandler的完整源代码
public class MandatoryWarningHandler {
...
public MandatoryWarningHandler(Log log, boolean verbose,
boolean enforceMandatory, String prefix,
LintCategory lc) {
this.log = log;
this.verbose = verbose;
this.prefix = prefix;
this.enforceMandatory = enforceMandatory;
this.lintCategory = lc;
}
...
}