绕过 Scala 2.11 中的弃用警告

Bypassing deprecation warnings in Scala 2.11

invoking the deprecated method from a deprecated local def 提供了一种避免 Scala 2.10(及之前)中的弃用警告的好方法。不幸的是,它在 Scala 2.11 中不起作用。有替代品吗?

this Scala issue comment 开始,我们可以在已弃用的 class/trait 中定义调用已弃用 API 的方法,并让此 class 的伴随对象在没有警告的情况下扩展它:

scala> @deprecated("", "") def foo = 0
foo: Int

scala> object Test { @deprecated("", "") class Coral { def fooForwarder = foo }; object Coral extends Coral }
defined object Test

scala> Test.Coral.fooForwarder
res1: Int = 0