scala 实际上抑制了编译器警告
scala actually suppress compiler warnings
我怎样才能真正抑制编译器警告:
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",
您应该从您调用 kryo.register
的块中显式 return Unit
。如果没有块,则将其包裹在一个中:
{
kryo.register(classOf[Foo])
kryo.register(classOf[Bar])
() // I know what I'm doing
}
关于一般警告抑制
不幸的是,Scala 没有内置的抑制系统。人 have been asking for this 但实现起来并非易事。目前有两个选择:
- 完全禁用警告
- 使用编译器插件:silencer
我怎样才能真正抑制编译器警告:
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",
您应该从您调用 kryo.register
的块中显式 return Unit
。如果没有块,则将其包裹在一个中:
{
kryo.register(classOf[Foo])
kryo.register(classOf[Bar])
() // I know what I'm doing
}
关于一般警告抑制
不幸的是,Scala 没有内置的抑制系统。人 have been asking for this 但实现起来并非易事。目前有两个选择:
- 完全禁用警告
- 使用编译器插件:silencer