如何实际抑制编译器警告:
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",
答案 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,但实现起来并不容易。目前有两种选择: