This article Evolving Java With ––enable–preview aka Preview Language Features describes what is the main purpose why this warning cannot be disabled.
Imagine everybody started experimenting with preview features (or
incubator modules, for that matter) and then spreading that code and
the artifacts around. When a feature changes, they become outdated
after just a few months and maintaining such dependencies would become
a nightmare. Don’t worry, though, there are a number of safeguards
preventing exactly that. Well, from happening accidentally at least.
This additional link shows what @SuppressWarning
values are supported by the latest Eclipse IDE
UPDATE
Here is the OpenJDK's source code which is proves this warning is always enabled.
full source of Preview class
public class Preview {
/** flag: are preview features enabled */
private final boolean enabled;
/** the diag handler to manage preview feature usage diagnostics */
private final MandatoryWarningHandler previewHandler;
/** test flag: should all features be considered as preview features? */
private final boolean forcePreview;
/** a mapping from classfile numbers to Java SE versions */
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();
}
...
}
The mandatoriness was hardcoded at the 3rd parameter (enforceMandatory
) of MandatoryWarningHandler
's.
Full source of MandatoryWarningHandler
public class MandatoryWarningHandler {
...
/**
* Create a handler for mandatory warnings.
* @param log The log on which to generate any diagnostics
* @param verbose Specify whether or not detailed messages about
* individual instances should be given, or whether an aggregate
* message should be generated at the end of the compilation.
* Typically set via -Xlint:option.
* @param enforceMandatory
* True if mandatory warnings and notes are being enforced.
* @param prefix A common prefix for the set of message keys for
* the messages that may be generated.
* @param lc An associated lint category for the warnings, or null if none.
*/
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;
}
...
}