scala – 如何弃用案例类的伴随对象?

我注意到如果不推荐使用case类,那么它的伴随对象不会.

scala> @deprecated case class A(x: Int)
warning: there was one deprecation warning; re-run with -deprecation for details
defined class A

scala> A(0)
res0: A = A(0)

scala> new A(0)
warning: there was one deprecation warning; re-run with -deprecation for details
res1: A = A(0)

我想得到A(0)的警告,就像我得到新的A(0)一样.我应该明确定义伴随对象并弃用它吗?有没有更好的方法?

最佳答案

Should I define the companion object explicitly and deprecate it ?

显然是这样!根据https://issues.scala-lang.org/browse/SI-2799,它应该被自动弃用(这对我来说很有意义),但它似乎不再存在.

点赞