为什么我不能禁止包装上的警告? [英] Why Can't I SuppressWarnings on a Package?

查看:66
本文介绍了为什么我不能禁止包装上的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从javadoc中看到, @SuppressWarnings 注释适用到

I see from the javadoc that the @SuppressWarnings annotation applies to

TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE

目标.为什么它还不适用于PACKAGE?

targets. Why does it not also apply to PACKAGE?

我有一些生成的代码,其中包含一些原始类型警告.我希望能够为生成的类添加一个package-info.java文件(在单独的物理目录中,但使用相同的Java包),该文件告诉eclipse忽略从包中生成的类发出的任何原始类型警告.

I have some generated code which contains some raw types warnings. I'd like to be able to add a package-info.java file for the generated classes (in a separate physical directory but the same java package) which tells eclipse to ignore any raw types warnings emanating from the generated classes in package.

为什么不支持此功能?是否有另一种方法来抑制整个包装中的警告?

Why is this not supported? Is there an alternate way of suppressing a warning in an entire package?

推荐答案

在对旧错误报告的响应(状态-已关闭,无法修复)中解释了不允许在包级别抑制警告的原因:允许在软件包级别指定SuppressWarning .

The reason that suppressing warnings at the package level is not allowed was explained in the response to an old bug report (Status - Closed, Will Not Fix): Allow SuppressWarnings to be specified at the package level.

这些警告实际上表明了 生成的代码.

The warnings actually indicates potential problems in the generated code.

当前,SuppressWarnings具有以下理想的属性: 仅影响词汇嵌套代码.这意味着你 可以立即查看是否可以取消警告 您正在阅读的代码.

Currently, SuppressWarnings have the desirable property of only affecting lexically nested code. This means that you can immediately see if a warning might be suppressed in code you're reading.

此提案将违反此属性,以解决不常见的问题 在大多数情况下都可以解决的问题.

This proposal would violate this property to solve an uncommon problem which in most cases can be worked around.

在该回复中还建议了一些解决方法.

There are a couple of work arounds suggested in that response as well.

  1. 使用-source 1.4和-target 5自行编译生成的代码.

  1. compile the generated code by itself using -source 1.4 and -target 5.

请求使用抑制警告的javacc的更新版本 或不生成导致警告的代码.

request an updated version of javacc which either uses suppresswarnings or doesn't generate code which causes warnings.

我认为将生成的代码放入自己的项目中的第一个建议应该对您有用.第二个建议看起来更像是针对错误报告中的问题的.我不知道您是否使用javacc.

I think the first suggestion, putting the generated code in its own project, should work for you. The second suggestion looks like its more specific to the problem in the bug report. I don't know if you're using javacc or not.

这篇关于为什么我不能禁止包装上的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆