1

在 Scala 2.10(及之前)中有一种避免弃用警告的好方法从已弃用的本地 def 调用已弃用的方法来避免弃用警告。不幸的是,它在 Scala 2.11 中不起作用。有替代方案吗?

4

1 回答 1

1

这个 Scala 问题评论中,我们可以在已弃用的类/特征中定义调用已弃用 API 的方法,并让此类的伴随对象扩展它而不会发出警告:

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
于 2015-05-23T09:32:39.600 回答