Scala 中是否有相当于 SuppressWarnings 的功能?
我想知道scala是否有相当于java的 @ SuppressWarnings 可以应用于函数或其他任何东西来忽略函数发出的任何弃用警告[1]?
1:在我的情况下,相关警告是:Thread类中的方法停止已被弃用:请参阅相应的Javadoc以获取更多信息。
我知道停止的问题,但仍然存在一些情况,由于遗留代码我们必须使用它。
I was wondering if scala had an equivalent to java's @SuppressWarnings that can be applied to a function or whatever to ignore any deprecation warnings[1] that function emits?
1: Relevant warning in my case is: method stop in class Thread is deprecated: see corresponding Javadoc for more information.
I am aware of the problems with stop however there are still some cases where due to legacy code we have to use it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
否,针对此类功能的增强请求 [1] 被关闭为
wontfix
。我同意这会有用。我预计 Scala 核心团队不会反对这个想法,但他们的资源有限,而且有许多更高的优先级。
更新:此功能最终在 2020 年 4 月 22 日的 scala 2.13.2 版本中实现,请参阅此答案
[1] https://issues.scala-lang.org/browse /SI-1781
No, and an enhancement request [1] for such a feature was closed as
wontfix
.I agree it would be useful. I expect that the Scala core team aren't against the idea, but they have finite resources and many higher priorities.
update: this feature was eventually implemented in scala 2.13.2 release on 2020-04-22, see this answer
[1] https://issues.scala-lang.org/browse/SI-1781
编辑:您应该使用@nowarn
为此有一个简单的编译器插件:消音器(有点无耻的插件)
EDIT: You should use @nowarn
There is a simple compiler plugin for this: silencer (a bit shameless plug)
Scala 2.13.2 提供
@ nowarn
注释是在 ghik 的silencer
基础上开发的,例如不会引发任何警告,同时
给出
Scala 2.13.2 provides
@nowarn
annotation developed on the basis of ghik'ssilencer
, for exampleraises no warnings, whilst
gives
以下是如何抑制 sbt 中的所有警告:
Here is how to suppress all warnings in sbt: