当我使用JDK 1.7.0在OS X上编译Spring JDBC源代码时,我收到此警告:
warning: CachedRowSetImpl is internal proprietary API and may be removed in a future release
Run Code Online (Sandbox Code Playgroud)
如何在编译期间禁止显示警告消息?
我已经知道并使用Java的@SuppressWarning注释.我正在寻找具体用法来抑制我所描述的警告.
我的问题具体是,在这行代码中:
@SuppressWarnings("valuegoeshere")
Run Code Online (Sandbox Code Playgroud)
应该用"valuegoeshere"替换什么?
编辑:人们,我知道最好避免导致警告的代码.通常这将是我的方法.但是我在这里编译第三方代码,我不想重写.我只想添加正确的注释来抑制警告,以便我可以实际做些什么的警告不会被埋没.
Joh*_*ica 46
无法抑制此特定警告.至少不正式.
有关专有API的警告意味着您不应使用导致警告的API.Sun不支持此类API,并且警告不会被禁止.
如果您特别确定,可以使用高度未记录的javac -XDignore.symbol.file标志,该标志将针对Sun的内部rt.jar而不是面向公众的符号文件编译您的程序ct.sym.rt.jar没有产生这个警告.
Rea*_*ted 20
如果您使用的是maven,则可能有兴趣将以下内容添加到您的pom.xml文件中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-XDignore.symbol.file</compilerArgument>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Wil*_*ung 11
看到这个答案
测试代码
@SuppressWarnings("sunapi")
sun.security.x509.X509CertImpl test;
Run Code Online (Sandbox Code Playgroud)
编译命令行
javac test.java -Werror -Xlint:sunapi -XDenableSunApiLintControl
Run Code Online (Sandbox Code Playgroud)
要么
javac test.java -Werror -Xlint:all -XDenableSunApiLintControl
Run Code Online (Sandbox Code Playgroud)
编译通过没有任何警告
删除SuppressWarnings标记并再次编译
然后报告错误
test.java:4: warning: X509CertImpl is internal proprietary API and may be removed in a future release
sun.security.x509.X509CertImpl test;
^
error: warnings found and -Werror specified
1 error
1 warning
Run Code Online (Sandbox Code Playgroud)