scala实际上压制编译器警告

时间:2017-12-19 20:19:57

标签: scala warnings compiler-warnings scalac

如何实际抑制编译器警告:

discarded non-Unit value
[warn]     kryo.register(classOf[Foo])

Suppress "discarded non-Unit value" warning的建议不适用,因为问题发生在我自己的代码之外。

修改

编译器选项是:

"-target:jvm-1.8",
  "-encoding",
  "UTF-8",
  "-feature",
  "-unchecked",
  "-deprecation",
  "-Xfuture",
  "-Xlint:missing-interpolator",
  "-Yno-adapted-args",
  "-Ywarn-dead-code",
  "-Ywarn-numeric-widen",
  "-Ywarn-value-discard",
  "-Ywarn-dead-code",
  "-Ywarn-unused"

会警告"-Ywarn-value-discard",

1 个答案:

答案 0 :(得分:3)

您应该从您调用Unit的块中明确返回kryo.register。如果没有阻塞,请将其包装成一个:

{
  kryo.register(classOf[Foo])
  kryo.register(classOf[Bar])
  () // I know what I'm doing
}

关于一般的警告抑制

不幸的是,Scala没有内置的抑制系统。人have been asking for this,但实现起来并不容易。目前有两种选择:

  1. 完全停用警告
  2. 使用编译器插件:silencer