Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java “如何禁用”;警告:[未选中]未选中的转换“;不修改源_Java_Ant - Fatal编程技术网

Java “如何禁用”;警告:[未选中]未选中的转换“;不修改源

Java “如何禁用”;警告:[未选中]未选中的转换“;不修改源,java,ant,Java,Ant,我在一个库中收到“警告:[未选中]未选中转换”消息,我正在编译该库的源代码。由于我不想修改库源代码,有没有办法在Ant的javac任务中禁用该警告?试试这个 <javac classpathref="project.class.path"> nowarn="true" deprecation="false" .... </javac> nowarn=“正确” deprecation=“false” .... 您应该尝试javac选项-Xlint:-n

我在一个库中收到“警告:[未选中]未选中转换”消息,我正在编译该库的源代码。由于我不想修改库源代码,有没有办法在Ant的
javac
任务中禁用该警告?

试试这个

<javac classpathref="project.class.path">
   nowarn="true"
   deprecation="false"
   ....
</javac>

nowarn=“正确”
deprecation=“false”
....

您应该尝试javac选项
-Xlint:-name
其中name是要禁用的警告的名称。给出了可能的名称列表。所以我猜在你的情况下,名字应该是“未选中的”

在Ant脚本中,这看起来像:

<javac ...>
  <compilerarg value="-Xlint:-unchecked"/>
  ...
</javac>

...

无法禁用
未选中的
Xlint选项,至少不使用
-Xlink:-unchecked
javac标志

这似乎是在编译器的
com.sun.tools.javac.comp.Check
类中强制执行的,请参见
jdk8-b40
标记的第127行(以下摘录)


我正试图禁用那个特别的警告。啊!我不认为有一种方法可以在不注释它或禁用所有其他警告的情况下禁用该特定警告。如果您不打算修改库源代码,那么我能想到的唯一解决方法就是将库编译成一个jar,然后简单地针对该jar进行链接。或者使用两个不同的javac任务编译所有内容,一个用于库,另一个用于其他任务。将
-Xlint:-unchecked
传递给编译器不起作用。请参阅。要摆脱
警告:[未选中]未选中的转换,请改为获取
注意:。。。使用未经检查或不安全的操作。注意:使用-Xlint:unchecked重新编译以获取详细信息。
您只需删除
-Xlint:unchecked
,正如@timothymcarthy所提到的,
-Xlint:-unchecked
不起任何作用。该选项的文档描述为“提供Java语言规范强制要求的未经检查的转换警告的更多详细信息。”
    boolean verboseDeprecated = lint.isEnabled(LintCategory.DEPRECATION);
    boolean verboseUnchecked = lint.isEnabled(LintCategory.UNCHECKED);
    boolean verboseSunApi = lint.isEnabled(LintCategory.SUNAPI);
    boolean enforceMandatoryWarnings = source.enforceMandatoryWarnings();

    deprecationHandler = new MandatoryWarningHandler(log, verboseDeprecated,
            enforceMandatoryWarnings, "deprecated", LintCategory.DEPRECATION);
    uncheckedHandler = new MandatoryWarningHandler(log, verboseUnchecked,
            enforceMandatoryWarnings, "unchecked", LintCategory.UNCHECKED);
    sunApiHandler = new MandatoryWarningHandler(log, verboseSunApi,
            enforceMandatoryWarnings, "sunapi", null);